Unit 4 · Association, Aggregation and Composition

4.4Comparing the Three

AspectAssociationAggregationComposition
Meaninguses / knowshas-a (shared parts)owns / part-of
StrengthWeakestMediumStrongest
LifetimeIndependentParts outlive wholeParts die with whole
Who creates the partAnyoneOutside the wholeThe whole itself
ExampleTeacher–StudentDepartment–TeacherHouse–Room
UML symbolPlain lineHollow diamond at the wholeFilled diamond at the whole
AssociationweakestTeacherStudentindependent lifetimesTeacher and Studentexist separatelyAggregationmediumDepartmentTeacherparts outlive the wholeTeacher stays if thedepartment closesCompositionstrongestHouseRoomparts die with the wholeRooms go when thehouse is demolishedplain line · hollow diamond · filled diamond (the diamond sits at the whole)
Association, aggregation and composition compared: notation, examples and lifetimes

One example, three relationships

In a hospital system:

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.

In this section