OOPS(OBJECT ORIENTED PROGRAMMING)  

Posted by ROCKING GUY in

OOPS
Class :
 A class is a user-defined data type which holds both the data and functions to operate on that data. The internal data of a class is called member data and functions are called member functions or mthods of class. The variables of the class type are often called objects or instances. Thus, a class is a definition of an object.
The class construct provides support for data hiding, abstraction, encapsulation, inherritance, polymorphism and public interface functions for passing messages between objects.
Concepts of OOPs terminology / Components of OOPs
1. Data Abstraction : 
In OOPs data abstraction is defined and the collection of data and methods.
2. Data Hiding : 
In C++, class construct allows to declare data and methods as public, private or protected group. The implementation details of class can be hidden. Private data of a class is also hidden to outside world i.e. private data of a class cannot be accessed outside the class. The only way to excess this private data of a class is by invoking the public methods/functions of the class. This is done by data hiding principle.
3. Data encapsulation :
The internal data of the class is first separated from outside world. The are the put along with the member functions in a capsule. In other words, encapsulation groups all the pieces of the object into one clean package. it avoids undesired side effects of member data when it is defined outside the class and also protects from the intentional misuse of important data. hence providing a kind of security to the object..
4. Inheritance:
C++ allows programmers to build hierarchy of classes. The features of class can be passed onto another class. Thus, the object of one class may acquire the properties of other calls as well as its own independent properties. Concept of inheritance provides the idea of reusability. i.e. a new class can be derived from existing class. There are many types of inheritance we will discuss later. 

The new class, which is derived from other class, is called derived class and the class from which it is derived is called base class.


Syntax to inherit properties of class named class1 in the new class named class2 

 Class class2 extends public class1
 {
 members of class 2;
 ---------------------
 ---------------------
}


5. Dynamic Binding
Dyanmic binding means that the code associated with given procedure call is not known until the time of call at runtime. It is associated with polymorphism and inheritance.

6. Polymorphism:
Polymorphism is the ability to take more than one form. An operation may exhibit different behaviour in different instances. The behaviour depends on the type of data used in the operation. C++ allows a family of functions having same name but they must differ in number or type of arguments passed, and the function will be called according to the proper match of parameters
e.g. in the example given below

int max(int,int); //form 1
float max(float,float); //form 2
int max(int,int,int); //form 3


int max(int p,int q) // definition of form 1
{
if(p>q) 
return(p);
else
return(q);
}

float max(float p,float q) // definition of form 2 
{
if(p>q) 
return(p);
else
return(q);
}

int max(int p,int q,int r) // definition of form 3
{
if(p>q && p>r)
return(p);
else if(q>r)
return(q);
else
return(r );
}

This entry was posted on Saturday, December 20, 2008 at 5:28 AM and is filed under . You can follow any responses to this entry through the comments feed .

0 comments

Post a Comment