Friday, March 18, 2011

What are the three pillars of OOD?

(1) Encapsulation:
The ability to combine attributes (data) and functionality (methods) into a single entity (class).

(2) Inheritance:
The ability to extend (subclass) a base class, i.e. the capability of a class to use the properties and methods of another class while adding its own functionality.

(3) Polymorphism:
From the biological term 'many forms'

The capability of an action or method to do different things based on the object that it is acting upon.

Example:

(i) Overloaded methods - methods with the same name but different signatures i.e. either a different number or type of parameters or a different return type.

(ii) Overridden methods - methods that exist in a base class and then redefined within an inherited or subclass. They have the same signature and the subclass definition is used i.e. the subclass definition overrides the definition in the base class.

No comments:

Post a Comment