Command Palette

Search for a command to run...

PHASE 1Beginner ~6 min· topic 3 of 5

Topic 1.3

UML / Class Relationships

In one line

Interviews rarely ask you to draw formal UML, but the relationship vocabulary (1:1, 1:N, N:N, association, aggregation, composition, inheritance, dependency) is used constantly to describe a class diagram out loud.

0/5 · 0%

Think of it like this

A family tree for code. It shows who owns whom (a House owns its Rooms), who just knows whom (a Doctor knows a Patient), and who is a kind of whom (a Dog is an Animal).

Key ideas

  1. 01

    1:1 — one instance references exactly one other (Customer ↔ Passport).

  2. 02

    1:N — one references many (Order 1—many LineItem). The 'many' side holds the FK.

  3. 03

    N:N — both sides hold collections (Student ↔ Course) via a join/associative table.

  4. 04

    Association: a structural reference, either direction, no ownership (Doctor → Patient).

  5. 05

    Aggregation: whole/part, parts can outlive the whole (Team ▷ Player).

  6. 06

    Composition: whole/part with ownership and life-cycle coupling (House ◇ Room; house dies, rooms die).

  7. 07

    Inheritance: 'is-a', drawn as an empty triangle arrow to the parent.

  8. 08

    Dependency: dashed arrow meaning 'uses briefly' (method parameter, local variable).

  9. 09

    When describing your LLD out loud, always name the multiplicity and the ownership.

Java / Spring map

  • →

    Composition → private final field constructed inside the owner.

  • →

    Aggregation → field injected from outside (Spring constructor injection).

  • →

    Association → a reference field or method parameter with no life-cycle claim.

  • →

    Dependency → usage inside a method body: new Receipt(price).

Explain without notes

01

Draw Parking Lot: Spot belongs to Floor (composition), Ticket references Spot (association). Name each arrow.

Practice

01

Model a Library: Book, Member, Loan. Identify the multiplicities and whether each link is composition, aggregation, or association.

Completion checklist

  • I can draw and explain all five relationship arrows with multiplicity.

Back to phase