Hey guys in this article, you will understand the difference between Aggregation and Composition with easy to understand examples
- Check the Complete Spring MVC Tutorials
- Check the Complete JSP Tutorials
- Check the Complete Spring Boot Tutorials [100+ Examples]
- Check the Complete Spring Boot and Thymeleaf Tutorial
- Check the Complete AWS Tutorial
- Check the Complete JavaServer Faces (JSF) Tutorial
- Check the Complete Spring Data JPA Tutorial
- Check the Complete Spring Security Tutorial
- Check the Spring Boot JdbcTemplate Tutorials
Aggregation vs Composition
Following are the difference between Aggregation and 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.|
– 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.
– 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.