Association agggregation and composition


Published on

1 Like
  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Association agggregation and composition

  1. 1. Disclaimer:This presentation is prepared by trainees ofbaabtra as a part of mentoring program. This is not officialdocument of baabtra –Mentoring PartnerBaabtra-Mentoring Partner is the mentoring division of baabte System Technologies Pvt .Ltd
  2. 2. Association aggregation and composition Jithin Mathew
  3. 3. They are the relationships among classes injava– Association– Aggregation– Composition
  4. 4. Association• It is a relationship between two objects.• In other words, association defines the multiplicity between objects.• You may be aware of one-to-one, one-to-many, many-to-one, many-to-many all these words define an association between objects.• Aggregation is a special form of association.• Composition is a special form of aggregation.
  5. 5. Association represents a general binary relationshipthat describes an activity between two classes
  6. 6. Another example for Association• Let’s take an example of Teacher and Student. Multiple students can associate with single teacher and single student can associate with multiple teachers but there is no ownership between the objects and both have their own lifecycle. Both can create and delete independently.
  7. 7. Aggregation• It is a special case of association.• A directional association between objects.• When an object ‘has-a’ another object, then you have got an aggregation between them.• Direction between them specified which object contains the other object.• It is also called ‘Has-a’ relationship.
  8. 8. Note: If you delete the parent object, even then the child object may exist. One object can contain the other, but there is no restriction that the composed object has to exist in order to have existence of child object.
  9. 9. Examples for aggregation• Take an example of Departments and developers. A developer can be only in one department like dotnet, java etc. but if we delete the Department object, still the Developer object exists. This is a “Has- a” relation.• Let’s take another example of Department and teacher. A single teacher can not belongs to multiple departments, but if we delete the department teacher object will not destroy.
  10. 10. Composition• It is a special case of aggregation.• In a more specific manner, a restricted aggregation is called composition.• When an object contains the other object, if the contained object cannot exist without the existence of container object, then it is called composition.
  11. 11. Example for composition• A class contains students. A student cannot exist without a class. There exists composition between class and students.
  12. 12. Difference between aggregation and composition• Composition is more restrictive.• When there is a composition between two objects, the composed object cannot exist without the other object.• This restriction is not there in aggregation. Though one object can contain the other object, there is no condition that the composed object must exist.
  13. 13. • The existence of the composed object is entirely optional.• In both aggregation and composition, direction is must. The direction specifies, which object contains the other object.
  14. 14. Example: A Library contains students and books. Relationship between library and student is aggregation. Relationship between library and book is composition. – A student can exist without a library and therefore it is aggregation. – A book cannot exist without a library and therefore its a composition.
  15. 15. Another Example• The relation between a car and a tyre is an aggregation because the tyre is still a tyre if it is not attached to a car. The tyre has a life of its own. It exists outside of a car and you can use it on another car.• The relation between a car and a carburetor is a composition because the carburetor has no use if it is out of a car.
  16. 16. Video link:You can refer more about this topic SEW1Q
  17. 17. Thankyou