Skip to content
Low Level Design Mastery Logo
LowLevelDesign Mastery

Aggregation

Weak ownership - parts can exist without the whole.

Aggregation is a “has-a” relationship where one class contains another, but the contained class can exist independently. It represents a weak ownership relationship.

Aggregation represents:

  • “Has-a” relationship (weak ownership)
  • Parts can exist independently of the whole
  • Parts can belong to multiple wholes
  • Lifecycle independence - parts aren’t destroyed when whole is destroyed
  • Weak ownership - Container doesn’t own the parts
  • Independent lifecycle - Parts can exist without container
  • Multi-ownership - Parts can belong to multiple containers
  • Hollow diamond in UML diagrams
Diagram
FeatureAggregationComposition
OwnershipWeakStrong
LifecycleIndependentDependent
Multi-ownershipYesNo
UML SymbolHollow diamondFilled diamond
ExampleUniversity → StudentsCar → Engine

Use Aggregation when:

  • Parts can exist without the whole
  • Parts can belong to multiple wholes
  • You need flexibility in relationships
  • Parts have independent lifecycle
  • Relationship is “part-of” but not essential

Examples:

  • University → Students (students can transfer)
  • Shopping Cart → Products (products exist independently)
  • Team → Players (players can change teams)
  • Library → Books (books can be removed)
  • Department → Employees (employees can move departments)

💡 Time to Practice!

Now that you understand the concepts, put them into practice with our interactive playground. Build UML diagrams, write code, and get AI-powered feedback.

Browse All Problems