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,
- Difference between Abstract Class and Interface in Java
- Difference between Abstraction and Encapsulation in Java
- Difference between Hashset and Treeset in Java
- Difference between == and .equals() method in Java
- Difference between Primitive and Object Data Types in Java
- Difference between Stack and Heap Memory in Java
- Difference between Throw and Throws in Java
- Difference between Abstraction and Encapsulation in Java
- Difference Between AWT and Swing in Java
- Differences between Checked and Unchecked Exceptions in Java
- Difference between Collection and Collections in Java
- Difference between Comparable and Comparator in Java
Comments