Ask two questions:
- Does one object contain the other as a part? If no, it is association.
- If yes: can the part exist meaningfully without the whole? Yes: aggregation. No: composition.
Tip: the answer depends on the system you are modelling. A Room may be a composition in a building-design system, but an aggregation in a hotel system if rooms can be moved between hotels.
Worked classification examples
| Pair | Is one a part of the other? | Can the part exist alone? | Relationship |
|---|---|---|---|
| Customer and Order | No: a customer places an order but does not contain it | (not asked) | Association |
| Playlist and Song | Yes: a playlist groups songs | Yes: the song exists in many playlists and outside them | Aggregation |
| Invoice and InvoiceLine | Yes | No: a line means nothing without its invoice | Composition |
| University and Department | Yes | Usually no: the department is created by and closed with the university | Composition |
| Department and Professor | Yes | Yes: a professor can move to another department | Aggregation |
| Driver and Car | No: the driver uses the car | (not asked) | Association |
| Car and Vehicle | "A Car is a Vehicle", so this is not has-a at all | (not asked) | Inheritance |
Check with code: if the part is created with new inside the whole and never handed out, it is composition. If it is passed in from outside, it is aggregation (or association, if it is not a part at all).
The classifier below gives you pairs to sort. Remember to try the is-a question first.