Difference between Aggregation and Composition in Java with Example





Hey guys in this article, you will understand the difference between Aggregation and Composition with easy to understand examples

Read More:

Aggregation vs Composition


Following are the difference between Aggregation and Composition

Aggregation Composition
Aggregation is a weak Association. Composition is a strong Association.
Class can exist independently without owner. Class can not meaningfully exist without owner.
Have their own Life Time. Life Time depends on the Owner.
A uses B. A owns B.
Child is not owned by 1 owner. Child can have only 1 owner.
Has-A relationship. A has B. Part-Of relationship. B is part of A.
Denoted by a empty diamond in UML. Denoted by a filled diamond in UML.
We do not use “final” keyword for Aggregation. “final” keyword is used to represent Composition.
Examples:
– Car has a Driver.
– A Human uses Clothes.
– A Company is an aggregation of People.
– A Text Editor uses a File.
– Mobile has a SIM Card.
Examples:
– Engine is a part of Car.
– A Human owns the Heart.
– A Company is a composition of Accounts.
– A Text Editor owns a Buffer.
– IMEI Number is a part of a Mobile.

That’s it for this post, if you like this post, share this with your friends and colleagues or you can share this within your social media platform. Thanks, I will see you in our next post.



About the author

Bushan Sirgur

Hey guys, I am Bushan Sirgur from Banglore, India. Currently, I am working as an Associate project in an IT company.

View all posts

Leave a Reply

Your email address will not be published. Required fields are marked *