Unit 4 · Association, Aggregation and Composition

4.4.1How to decide

Ask two questions:

  1. Does one object contain the other as a part? If no, it is association.
  2. If yes: can the part exist meaningfully without the whole? Yes: aggregation. No: composition.
Is one object a partof the other?Can the part existwithout the whole?YesNoAssociationYesAggregationNoComposition
Two questions decide the relationship

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

PairIs one a part of the other?Can the part exist alone?Relationship
Customer and OrderNo: a customer places an order but does not contain it(not asked)Association
Playlist and SongYes: a playlist groups songsYes: the song exists in many playlists and outside themAggregation
Invoice and InvoiceLineYesNo: a line means nothing without its invoiceComposition
University and DepartmentYesUsually no: the department is created by and closed with the universityComposition
Department and ProfessorYesYes: a professor can move to another departmentAggregation
Driver and CarNo: 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.