Sunday, January 29, 2012

Object Oriented Programming

Object Oriented Concepts


   Creating a class based on an existing base class or super type. As the title suggests, this concept defines reuse or the recreation of objects using an existing class.

In the programming world we realize this by defining a base class that contains a set of shared or common methods and then create subclasses that inherit from this class. These methods and properties are then automatically available in the subclass.

What can we achieve by Inheritance?
The implementation of a common method/methods can be reused or shared among the subclasses from the base class.


The basic principle behind abstraction is to hide the complex details and keep things simple.

In the programming world we realize this by defining a base abstract class that contains a method/methods with or without concrete  implementations.The subclasses that extend this abstract class may or may not in turn implement these methods.

What can we achieve by Abstraction?
As you will read later below, one of the principles of object oriented principles is to code to an interface rather than an implementation. Abstraction helps in coding to a interface or a super type giving you the flexibility to change the implementation at a later stage.


 Polymorphisms is a generic term that means 'many shapes'. In OOP's polymorphism is the ability to be able define multiple implementations for the same method call.

In the programming world we realize this by defining a common interface across various concrete class with different implementations.

Ad-hoc polymorphism: polymorphism is not the same as method overloading or method overriding 

What can we achieve by Polymorphism?
We can achieve interchangeability. That is we can easily change the behavior of a given method without the need to create a new type.


Simply means hiding information that does not need to be seen by others. An analogy can be made here with the notion of a capsule, which not only encloses its contents, but also protects it from the exterior environment.

In the programming world we realize this by the use of access modifiers. For example we can make the methods of  a class private thus making its implementation in accessible to other objects.

What can we achieve by Encapsulation?
We can reduce the dependency of objects on each other. For example we can prevent users from setting the internal data of the component into an invalid or inconsistent state.

Object oriented principles

1) Code to an interface rather than to an implementation
2) Favor composition over inheritance
3) Encapsulate what changes or varies


No comments: