| Aspect | Association | Aggregation | Composition |
|---|---|---|---|
| Meaning | uses / knows | has-a (shared parts) | owns / part-of |
| Strength | Weakest | Medium | Strongest |
| Lifetime | Independent | Parts outlive whole | Parts die with whole |
| Who creates the part | Anyone | Outside the whole | The whole itself |
| Example | Teacher–Student | Department–Teacher | House–Room |
| UML symbol | Plain line | Hollow diamond at the whole | Filled diamond at the whole |
One example, three relationships
In a hospital system:
- A Doctor treats Patients. Both exist independently, and a patient may see many doctors: association.
- A Ward has Patients. The patients are admitted from outside, and they still exist if the ward closes: aggregation.
- A Patient has a MedicalRecord that is created for that patient and means nothing without them: composition.
The same objects can be linked in different ways, and choosing correctly makes the code match the real situation: who creates whom, who may share what, and what disappears together.