Download the BYJU'S Exam Prep App for free GATE/ESE preparation videos & tests - Download the BYJU'S Exam Prep App for free GATE/ESE preparation videos & tests -

Difference between Aggregation and Composition in Java

Composition and Aggregation are the two forms of association (a relation between two separate classes which are established through their Objects.) Let’s figure out the differences between Aggregation and Composition in the article.

What is Aggregation?

Aggregation is a type of association. In Java, aggregation is a connection between two classes that can be defined as a “has-a” relationship.

What is Composition?

Composition is a type of association. In Java, a composition defines a part-of a relationship, and both the entities are connected to each other.

Difference between Aggregation and Composition in Java

S.No. Aggregation Composition
1. Association between two objects that illustrate the “has-a” relationship is called Aggregation. A composition defines a part-of a relationship, and both the entities are connected to each other.
2. Here the objects are independent of each other. Here, the objects are dependent on each other.
3. In the case of Aggregation, the child object will remain in the system even if we remove the parent object. In the case of Composition, the child object will get deleted if we delete the parent object.
4. We can define Aggregation through a filled diamond. We can define composition through an empty diamond.
5. Aggregation is a strong association Composition is a strong association
6. In Aggregation, children have their own lifetime. In Composition, children don’t have their own lifetime.

Keep learning and stay tuned to get the latest updates on GATE Exam along with GATE Eligibility Criteria, GATE 2023, GATE Admit Card, GATE Application Form, GATE Syllabus, GATE Cut off, GATE Previous Year Question Paper, and more.

Also Explore,

Comments

Leave a Comment

Your Mobile number and Email id will not be published.

*

*