Class Relationships & UML
Beginner · 15 min read · Low-Level Design, Foundations
Association, aggregation, composition, dependency and inheritance — and drawing them.
A class diagram is the "architecture diagram" of an LLD interview. You don't need full UML fluency, but you must distinguish the relationship types precisely — interviewers frequently ask "is that aggregation or composition?" — and draw them quickly and correctly.
The class box
The six relationships
Ordered from weakest to strongest coupling:
Reading a full diagram
Read it as: a library owns its catalog and member registry; a book (the title) has one or more physical copies; a loan links a member to a specific copy; fines are computed by a pluggable policy.
Sequence diagrams
For dynamic behaviour — "walk me through checkout" — a sequence diagram is clearer than prose:
Other diagrams you may meet
Interview questions
- What's the difference between association, aggregation and composition?
- How is dependency different from association?
- Why prefer unidirectional associations?
Further reading
Key takeaways
- Six relationships: dependency, association, aggregation, composition, realization, inheritance.
- Aggregation vs composition is about ownership and lifecycle, not diagram shapes.
- Prefer weaker coupling: dependency and association over inheritance; unidirectional over bidirectional.
- Use class diagrams for structure and sequence diagrams for flows; keep them to what matters.