Friday, 31 August 2012

What is Association,Composition and Aggregation?


 Association,Aggregation and Composition is a core concepts of oop about the relationship of different classes with slightly difference in each other.

Association: The two Classes has a relationship with each other but each class has its own life cycle and not rely on each other
for example class “A” may has multiple or single object of class “B” and Class “B” may also has multiple or single objects of class “A”.
 
Example: student has one or different departments and one department have one or more students and not depend on each other.
 

Aggregation: Aggregation is a special type of Association means each entity has its own life cycle but one of them rely on other
means class “A” has only single object of class “B” at a time but class “B” has multiple or single objects of class ”A”.
 
Example: Employee has only one company at a time and company may have one or multiple employees but both has different life cycle.
 

Composition: Composition is a special type of Aggregation means one entity of them rely on other i.e.  class “A” has only single object
of class “B” at a time but class “B” has multiple or single objects of class “A”
but when one entity destroy other also must destroy means one life cycle is depend on other.
 
Example: Room has only one house but house may have one or multiple rooms
but room has no existent without house so room life cycle depends on house.

 
Happy Coding :)