Saturday, April 6, 2013

What are four principles of OOP, How aggregation is different than Composition ?


There are 4 major principles that make an language Object Oriented.  These are Encapsulation, Data Abstraction, Polymorphism and Inheritance.

Encapsulation


Encapsulation is the mechanism of hiding of data implementation by restricting access to public methods.

Abstraction


Abstract means a concept or an Idea which is not associated with any particular instance. Using abstract class/interface we express the intent of the class rather than the actual implementation. In a way, one class should not know the inner details of another in order to use it, just knowing the interfaces should be good enough.

Inheritance


Inheritances expresses "is a" relationship between two objects. Using proper inheritance, In derived classes we can reuse the code of existing super classes.

Polymorphism


It means one name many forms. It is further of two types - static and dynamic. Static polymorphism is achieved using method overloading and dynamic polymorphism using method overriding.

What is aggregation, how is it different from composition ? 


Both of these are special type of association and differ only in weight of relationship.
Composition is stronger form of "is part of" relationship compared to aggregation "has a".
In composition, the member object can not exist outside the enclosing class while same is not true for Aggregation.

No comments:

Post a Comment

Your comment will be published after review from moderator