Friday, 19 October 2012

Association, Aggregation, Composition

There are 3 words which confuses every developer. So many time people ask in the interview.


Association:
Association keyword show the relationship between more than one entity, class or Object. The Relationship can be one to one , one to many and many to one.
it means two class are associated with each other via some relationship that called association.
Association can be shown by a "Arrow" sign.

Example: 1. Faculty and students are having association.
2. Students and library is having association.






Aggregation
Aggregation is a special form of the association. It shows "has-a" relationship of the object. A Objection has a another object.Like class has student object. If two object having "has-a" relationship then only we can get Aggregation.



Composition

Composition is a special form of the aggregation. when one object contains another object and contained object can't exist without the container object, called composition. Like A student object can't exist without class object. A relationship between class object and student object called composition.

So basically there is a difference between aggregation and composition is, in the composition contained object can't exist or alive without container object but in the aggregation it can exist.




1 comment:

  1. Thank you for brief explanations. How does delegation with composition works. Can you please explain with example.

    ReplyDelete