Association Vs Aggregation Vs Composition with JAVA
I found some great website to understand that.
with nice code
Association, Composition and Aggregation in Java
Understanding Association, Aggregation, and Composition
- simplest one
Association Vs Aggregation Vs Composition
In short,
1. Association
1.1. Association is a relation between two separate classes.1.2. Composition and Aggregation are the two forms of association.
1.3. Association can be one-to-one, one-to-many, many-to-one, many-to-many.
pic1. one-to-many association
2. Aggregation
2.1. it represents Has-A relationship2.2. Each class can have different life cycles.
pic2. Aggregation
3. Composition
3.1. it represents Part-of relationship3.2. Each class has same life cycles.
cf)
Aggregation vs Composition
- Dependency: Aggregation implies a relationship where the child can exist independently of the parent. For example, Bank and Employee, delete the Bank and the Employee still exist. whereas Composition implies a relationship where the child cannot exist independent of the parent. Example: Human and heart, heart don’t exist separate to a Human
- Type of Relationship: Aggregation relation is “has-a” and composition is “part-of” relation.
- Type of association: Composition is a strong Association whereas Aggregation is a weak Assocation.
0 comments