REQUIREMENTS & MODELING / OBJECT DESIGN BRIEF

Class diagrams

A UML class diagram shows the static structure of a design: classes with their key attributes and methods, interfaces, and the relationships between them (inheritance, implementation, association, aggregation, composition, dependency) with multiplicities like 1 or 0..*..

BeginnerPhase 03 / Topic 4 of 8ResponsibilitiesCollaborationsExtensibility
01

Overview

A UML class diagram shows the static structure of a design: classes with their key attributes and methods, interfaces, and the relationships between them (inheritance, implementation, association, aggregation, composition, dependency) with multiplicities like 1 or 0..*.

In LLD interviews, a quick class diagram on the whiteboard is the backbone of the discussion. It does not need perfect UML; it needs clear boxes, the important methods, the right relationship arrows, and multiplicities that encode rules ('a spot holds 0..1 vehicle').

A building floor plan

It shows rooms (classes), doors between them (relationships), and room sizes (attributes). It does not show people walking around; that is what sequence diagrams are for.

02

When to use it

  • Communicating a design before coding.
  • Checking responsibilities and dependencies visually.
  • Documenting modules in design reviews.
03

Where it shows up in interviews

Whiteboard design

Recognize it when: every LLD interview.

  • Design a parking lot
  • Design an elevator system
  • Design a library system
04

Where it is used in real software

Mermaid and PlantUML

Text-based diagrams embedded in Markdown docs and GitHub READMEs.

IDE diagram generation

IntelliJ can generate class diagrams from code to understand unfamiliar modules.

Design reviews

Architecture decision records often include a class or component diagram.

05

Key terms

Visibility
+ public, - private, # protected.
Inheritance / realization
Solid line with hollow triangle / dashed line with hollow triangle.
Association
Solid line: one class uses or knows another.
Aggregation / composition
Hollow diamond (shared parts) / filled diamond (owned parts).
Multiplicity
1, 0..1, *, 1..* on relationship ends.
06

How it works, step by step

  1. 1
    Draw core entities as boxes

    Name plus key fields.

  2. 2
    Add main methods

    Only those that express behavior.

  3. 3
    Add interfaces for variation points

    PricingStrategy, Notifier.

  4. 4
    Connect with the right relationship

    Composition for owned parts, association for references.

  5. 5
    Annotate multiplicities

    ParkingLot 1 -- * Floor.

07

Parking lot class diagram (text form)

Key relationships

Step 1 / 6
FromRelationshipToMultiplicity
ParkingLotcompositionFloor1 to 1..*
FloorcompositionParkingSpot1 to 1..*
ParkingSpotassociationVehicle0..1
Car, Truck, BikeinheritanceVehicle-
HourlyPricingrealizationPricingStrategy-
ParkingLotdependencyPricingStrategy1

NOWFrom: ParkingLot | Relationship: composition | To: Floor | Multiplicity: 1 to 1..*

The diagram encodes rules: a spot holds at most one vehicle, and floors cannot exist without the lot.

08

Implementation

classDiagram  class ParkingLot {    -floors: Floor[]    -pricing: PricingStrategy    +park(v: Vehicle) Ticket    +exit(ticketId: string) Money  }  class Floor { -spots: ParkingSpot[] +findSpot(size) ParkingSpot }  class ParkingSpot { -id: string -size: Size -vehicle: Vehicle +assign(v) +release() }  class Vehicle { <<abstract>> +plate: string +size() Size }  class PricingStrategy { <<interface>> +fee(ticket, exitTime) Money }   ParkingLot "1" *-- "1..*" Floor  Floor "1" *-- "1..*" ParkingSpot  ParkingSpot "1" --> "0..1" Vehicle  Vehicle <|-- Car  Vehicle <|-- Truck  PricingStrategy <|.. HourlyPricing  ParkingLot --> PricingStrategy
09

Complexity and performance

Boxes on the board6-12

Keep it readable.

Time~10 minutes

Iterate as you go.

10

Trade-offs

Precision vs speed

Perfect UML notation matters less than clear relationships and responsibilities.

Diagrams drift from code

Generate or keep diagrams as code (Mermaid) to stay current.

11

Variants and related techniques

Object diagrams

Snapshot of instances at runtime.

Package / component diagrams

Higher-level module structure.

12

Common mistakes

  • Listing every getter and setter.

    Fix: Show only meaningful behavior.

  • Wrong relationship types.

    Fix: Composition only when the part cannot exist without the whole.

  • Missing interfaces for variation.

    Fix: Show where new behavior plugs in.

13

Interview questions

Composition vs aggregation in a class diagram?

Composition (filled diamond) means the whole owns the part's lifecycle, like Floor and ParkingSpot. Aggregation (hollow diamond) means the part can exist independently, like Team and Player.

How detailed should an interview class diagram be?

Core entities, key attributes, meaningful methods, interfaces for extension points, relationships with multiplicities. Skip trivial getters and setters.

14

Practice problems

ProblemDifficultyWhat it trains
Draw a class diagram for a library systemEasyRelationships.
Draw a class diagram for an elevator systemMediumControllers and strategies.