Saturday, June 7, 2014

Characteristics of OOP

Objects are the basic entities in an OOP through which we perceive the world around us. We naturally see our environments as being composed of things which have both attributes and behavior .These attributes and behavior in real world are equivalent to data and function respectively in a program. Thus objects are the self contained entity that consists of both data and function.

A class is a description of a number of similar objects. Prince, Madona and Sting are members of the class “rock musician”. There is no one person called Rock Musician but specific people with specific names are members of this class if they possess certain characteristics.
Class defines a data type. It signifies what type of data and function will be included in the objects of that class. Defining a class doesn’t create an object but the class is the description of object’s attributes and behavior.
Eg. Person Class
            Attributes: name , age…..
            Behavior: speak(), listen()…..
After a class is defined objects are created as:
ClassName ObjectaName;
If employee is defined as a class, the object manager is created as
                        employee manager;
Each class describes a possibly infinite set of individual objects. Each object is said to be an instance of a class has its own value for each attributes but shares attributes name and operations with other instances of the class

Data abstraction and encapsulation
Wrapping up of data with functions in a class is encapsulation. It is most striking feature of the class. No other outer functions can access the data of this class instead these are only accessible only by the functions written the class. This insulation of data from direct access by the program is called information hiding or data hiding.  Abstraction refers to the act of representing essential features without including the background details or explanations.  e.g. Ram studies in CAB.

It is a process in which object of one class acquire the properties of another class. By the use of this, we can add additional features to an existing class without modifying it. This is possible by deriving new class from an existing one. New class will have combined feature of both the classes.
How polymorphism plays an important role in allowing objects having different internal structures to share the
same external interface. ‘Draw ( )’ method has been used by many classes like circle, box, triangle which has taken more than one form, so regarded in process of polymorphism.   Draw function should be overloaded so that it can take the appropriate arguments and perform the specific task depending upon the arguments that has been passed to it.

Dynamic Binding:
 Binding refers to the linking of a procedure call to the code to be executed in response to the call. Dynamic binding (late binding) means that the code associated with a given procedure call is not known until the time of the call at run-time. It is associated with polymorphism. If we consider the above example, then by inheritance, every object will have this procedure however, the algorithm is unique to each object and so the draw procedure will be refined in each class that defined the object. At run-time, the code matching the object under current reference will be called.

Message Passing:
 An OOP consists of a set of objects that communicate with each other. The process of programming in an OO language involves following basic steps: 
   - Creating classes that define objects and their behavior.
   - Creating objects from class definitions.
   - Establishing communication among objects.
Communication among object is by sending and receiving information much the same way as people pass messages to one another. Concept of message passing makes it easier to talk about building systems that directly model or simulate their real-world counterpart.
Message passing involves specifying the name of the object, name of the function (message) and the information to be sent.  Objects have a lifecycle. They can be created and destroyed. Communication with an object is feasible as long as it is alive.

No comments:

Post a Comment