LLD INTERVIEW WORKFLOW / OBJECT DESIGN BRIEF

Define relationships

Step 4: connect the entities.

IntermediatePhase 10 / Topic 4 of 8ResponsibilitiesCollaborationsExtensibility
01

Overview

Step 4: connect the entities. For each pair, decide the relationship type (association, aggregation, composition, inheritance, implementation, dependency), its direction (who references whom), and multiplicity (1, 0..1, *). Draw a quick class diagram with the key methods and interfaces.

Direction matters: bidirectional references are harder to keep consistent, so prefer one-way navigation where possible (Show has ShowSeats; ShowSeat does not need to point back). Across aggregates or large boundaries, reference by ID instead of object. Interfaces mark the variation points where patterns will plug in.

A family tree and a contact list

Some links are ownership (a parent's child in a family tree), some are acquaintances (contacts), and some are shared (members of a club). You also decide who keeps whose phone number.

02

When to use it

  • After assigning responsibilities.
  • Before writing code in an LLD interview.
  • Reviewing coupling in an existing design.
03

Where it shows up in interviews

Class diagram construction

Recognize it when: 'draw the class diagram'.

  • Design a movie ticket system
  • Design a parking lot
  • Design a library system
04

Where it is used in real software

UML class diagrams

Standard notation for relationships and multiplicities.

ORM mappings

@OneToMany, @ManyToOne, and cascade settings mirror relationship decisions.

Aggregate boundaries

DDD recommends references by ID across aggregates to limit coupling.

05

Key terms

Navigability
Direction you can traverse the relationship.
Multiplicity
How many instances participate.
Composition
Owned parts with shared lifecycle.
Reference by ID
Store an identifier instead of an object reference.
06

How it works, step by step

  1. 1
    Pick pairs from use cases

    Show-Screen, Show-ShowSeat, Booking-Show.

  2. 2
    Choose the type

    Composition if lifecycle is owned.

  3. 3
    Choose direction

    One-way unless both sides truly need to navigate.

  4. 4
    Set multiplicity

    Show 1 -- * ShowSeat.

  5. 5
    Mark interfaces

    PricingStrategy, PaymentGateway, Notifier.

07

Relationships in the movie ticket system

Chosen types and directions

Step 1 / 6
FromToTypeMultiplicity / notes
CinemaScreenComposition1 to *
ScreenSeatComposition1 to *
ShowMovie, ScreenAssociation* to 1 each
ShowShowSeatComposition1 to * (created per show)
BookingShowReference by ID* to 1
BookingServicePricingStrategy, PaymentGatewayDependency on interfacesInjected

NOWFrom: Cinema | To: Screen | Type: Composition | Multiplicity / notes: 1 to *

Booking stores showId rather than a Show reference, keeping aggregates independent.

08

Implementation

classDiagram  Cinema "1" *-- "*" Screen  Screen "1" *-- "*" Seat  Show "*" --> "1" Movie  Show "*" --> "1" Screen  Show "1" *-- "*" ShowSeat  ShowSeat --> Seat  Booking ..> Show : showId  BookingService --> PricingStrategy  BookingService --> PaymentGateway  PricingStrategy <|.. WeekendPricing  PaymentGateway <|.. StripeGateway
09

Complexity and performance

Relationships drawn~1-2 per entity

Keep the diagram readable.

Time~5-10 minutes

Iterate while coding.

10

Trade-offs

Object references vs IDs

References are convenient to navigate; IDs decouple aggregates and ease persistence.

Bidirectional convenience

Two-way links simplify queries but require keeping both sides in sync.

11

Variants and related techniques

Repositories for lookup

Resolve IDs through repositories instead of holding object graphs.

Association classes

A relationship with its own data (Enrollment between Student and Course).

12

Common mistakes

  • Everything referencing everything.

    Fix: One-way navigation and IDs across boundaries.

  • Inheritance where composition fits.

    Fix: Use is-a only for true subtypes.

13

Interview questions

Why reference by ID instead of object?

It decouples aggregates, avoids loading huge object graphs, keeps each aggregate's consistency boundary clear, and maps naturally to persistence.

When is a relationship composition?

When the part is created by and cannot exist without the whole, like ShowSeats for a Show or Seats in a Screen, so deleting the whole deletes the parts.

14

Practice problems

ProblemDifficultyWhat it trains
Relationships for a food delivery systemEasyMultiplicities.
Relationships for a hotel booking systemMediumIDs vs references.