Association
Association in terms of objects refers to "has a" relationship between two related objects. For example, a employee has a communication address.
class Employee {
String name;
Address communicationAddress;
}
class Address {
String address;
}Aggregation
Aggregation in terms of objects refers to "has a"+ relationship between two related objects. For example, a department has multiple employees. It refers to having a collection of child objects in parent class. For example:
class Department {
String name;
List<Employee> employees;
}
class Employee {
String name;
}| Sr. No. | Key | Association | Aggregation |
|---|---|---|---|
| 1 | Definition | Association refers to "has a" relationship between two classes which use each other. | Aggregation refers to "has a"+ relationship between two classes where one contains the collection of other class objects. |
| 2 | Flexibility | Inflexible in nature. | Flexible in nature. |
| 3 | Linkage | Linkage is needed to maintain association. | Linkage between objects in not mandatory. |
| 4 | UML | Lines are used to represent association. | Diamond shape next to assembly class is used to represent the aggregation relationship. |