Make Money Online

RAP Bank

Wednesday, January 21, 2009

Features of Object Orientation

Abstraction

When you go to buy a washing machine, you will concentrate on the features that a particular brand of washing machine offers, like the wash mode and the color, in the context of your requirements. However, if an engineer comes home to repair your washing machine, he would concentrate on the "inside" of the machine, the working of the different components of the machine, and the item code of the part to be replaced.


Here, you as a user of the washing machine concentrate on the essential attributes and behaviors from your point of view, whereas the engineer views the washing machine at a different level of detail.


Abstraction, therefore, represents the essential characteristics of an object/class that differentiates it from other objects/classes with respect to the viewer's perspective.

Inheritance

Inheritance is a mechanism, which helps you to generalize common attributes and behaviors in separate classes from which various subclasses can be derived.
For example, the "Automatic Washing Machine" class is a subclass of the "Washing Machine” class and needs to contain only those attributes and behaviors that are specific to it. Other attributes and behaviors can be inherited from the "Washing Machine" class.

Encapsulation

Encapsulation helps you to hide unnecessary behaviors/attributes from the user and show only those attributes/behaviors that the users can directly use.


For example, the users of the washing machine need not know the intricacies of the internal working of the washing machine. They only need to know certain functions like switch on/off, wash mode settings etc.

Polymorphism

Polymorphism is the ability of an object to behave differently under different circumstances.
For example, Joseph Picardo's washing machine is an object of the "Washing machine" class. It behaves differently based on the mode setting. If the mode setting is "Wash", the machine carries out the washing operation, whereas if the mode setting is "Spin Dry" a different action is performed.

No comments: