Overview
UML (Unified Modeling Language) diagrams help visualize system design. In LLD interviews, you’ll mainly use Class Diagrams and Sequence Diagrams.Class Diagrams
Class diagrams show the static structure of a system.Basic Notation
Copy
┌─────────────────────────────────┐
│ <<interface>> │ ◄── Stereotype
│ Flyable │
├─────────────────────────────────┤
│ │ ◄── Attributes (empty for interface)
├─────────────────────────────────┤
│ + fly(): void │ ◄── Methods
└─────────────────────────────────┘
┌─────────────────────────────────┐
│ Bird │ ◄── Class Name
├─────────────────────────────────┤
│ - name: String │ ◄── Private attribute
│ # age: int │ ◄── Protected attribute
│ + species: String │ ◄── Public attribute
├─────────────────────────────────┤
│ + fly(): void │ ◄── Public method
│ - sleep(): void │ ◄── Private method
│ # eat(food: Food): void │ ◄── Protected method
└─────────────────────────────────┘
Visibility Symbols
| Symbol | Meaning | Access |
|---|---|---|
+ | Public | Everywhere |
- | Private | Same class only |
# | Protected | Same class + subclasses |
~ | Package | Same package |
Relationships
Copy
1. INHERITANCE (is-a)
────────────────────────▷
(Empty triangle arrow pointing to parent)
Example: Dog ────────▷ Animal
Dog IS AN Animal
2. IMPLEMENTATION (realizes)
- - - - - - - - - - - -▷
(Dashed line with empty triangle)
Example: Bird - - - - ▷ Flyable
Bird IMPLEMENTS Flyable
3. ASSOCIATION (knows-about)
─────────────────────────
(Simple line)
Example: Teacher ───── Student
Teacher KNOWS Student
4. AGGREGATION (has-a, weak)
◇─────────────────────────
(Empty diamond at container)
Example: Team ◇───── Player
Team HAS Players (players can exist without team)
5. COMPOSITION (has-a, strong)
◆─────────────────────────
(Filled diamond at container)
Example: House ◆───── Room
House HAS Rooms (rooms don't exist without house)
6. DEPENDENCY (uses)
- - - - - - - - - - - - ->
(Dashed arrow)
Example: Order - - - -> PaymentService
Order USES PaymentService
Multiplicity
Copy
1 Exactly one
0..1 Zero or one
* Zero or more
1..* One or more
n Exactly n
n..m Between n and m
Complete Example: E-commerce System
Copy
┌──────────────────────────┐
│ <<interface>> │
│ PaymentMethod │
├──────────────────────────┤
├──────────────────────────┤
│ + pay(amount): bool │
│ + refund(id): bool │
└──────────────────────────┘
△
│
│ implements
┌───────┴───────┐
│ │
┌───┴───────────┐ ┌┴──────────────┐
│ CreditCard │ │ PayPal │
├───────────────┤ ├───────────────┤
│ - cardNumber │ │ - email │
│ - cvv │ │ - password │
├───────────────┤ ├───────────────┤
│ + pay() │ │ + pay() │
│ + refund() │ │ + refund() │
└───────────────┘ └───────────────┘
┌───────────────────┐ ┌───────────────────┐
│ Customer │ │ Order │
├───────────────────┤ ├───────────────────┤
│ - id: UUID │ 1 │ - id: UUID │
│ - name: String │◆────────│ - status: Status │
│ - email: String │ * │ - createdAt: Date │
├───────────────────┤ ├───────────────────┤
│ + placeOrder() │ │ + calculateTotal()│
│ + getOrders() │ │ + cancel() │
└───────────────────┘ └─────────┬─────────┘
│
│ 1..*
◆
┌─────────┴─────────┐
│ OrderItem │
├───────────────────┤
│ - quantity: int │
│ - price: Decimal │
├───────────────────┤
│ + getSubtotal() │
└─────────┬─────────┘
│
│ *..1
│
┌─────────┴─────────┐
│ Product │
├───────────────────┤
│ - id: UUID │
│ - name: String │
│ - price: Decimal │
│ - stock: int │
├───────────────────┤
│ + reserve() │
│ + release() │
└───────────────────┘
Sequence Diagrams
Sequence diagrams show how objects interact over time.Basic Elements
Copy
┌──────┐ ┌──────┐ ┌──────┐
│Client│ │Server│ │ DB │
└──┬───┘ └──┬───┘ └──┬───┘
│ │ │
│ 1. request() │ │
│────────────────>│ │
│ │ 2. query() │
│ │────────────────>│
│ │ │
│ │ 3. result │
│ │<- - - - - - - - │
│ 4. response │ │
│<- - - - - - - - │ │
│ │ │
Legend:
─────────────> Synchronous call
- - - - - - -> Return/Response
═════════════> Async message
┌─────────────┐
│ Activation │ (box on lifeline = processing)
└─────────────┘
Complete Example: Order Checkout
Copy
┌────────┐ ┌───────────┐ ┌────────────┐ ┌─────────┐ ┌───────────┐
│ User │ │ Cart │ │ Checkout │ │ Payment │ │ Inventory │
└───┬────┘ └─────┬─────┘ └──────┬─────┘ └────┬────┘ └─────┬─────┘
│ │ │ │ │
│ checkout() │ │ │ │
│─────────────>│ │ │ │
│ │ │ │ │
│ │ createOrder() │ │ │
│ │───────────────>│ │ │
│ │ │ │ │
│ │ │ reserveItems() │
│ │ │─────────────────────────────>
│ │ │ │ │
│ │ │ │ reserved │
│ │ │<- - - - - - - - - - - - - - │
│ │ │ │ │
│ │ orderCreated │ │ │
│ │<- - - - - - - -│ │ │
│ │ │ │ │
│ enterPayment │ │ │ │
│<- - - - - - -│ │ │ │
│ │ │ │ │
│ paymentInfo │ │ │ │
│─────────────>│ │ │ │
│ │ │ │ │
│ │ processPayment() │ │
│ │───────────────────────────────> │
│ │ │ │ │
│ │ │ │ charge() │
│ │ │ │─────────────>│
│ │ │ │ (external) │
│ │ │ │ │
│ │ │ success │ │
│ │<- - - - - - - - - - - - - - - │ │
│ │ │ │ │
│ │ confirmOrder() │ │ │
│ │───────────────>│ │ │
│ │ │ │ │
│ │ │ commitInventory() │
│ │ │─────────────────────────────>
│ │ │ │ │
│ confirmation│ │ │ │
│<- - - - - - -│ │ │ │
│ │ │ │ │
Alt/Opt/Loop Fragments
Copy
┌─────────────────────────────────────────────────┐
│ alt [payment successful] │
│ ┌─────────────────────────────────────────┤
│ │ confirmOrder() │
│ │ sendConfirmationEmail() │
├───────┼─────────────────────────────────────────┤
│ │ [payment failed] │
│ ├─────────────────────────────────────────┤
│ │ releaseInventory() │
│ │ showError() │
└───────┴─────────────────────────────────────────┘
┌─────────────────────────────────────────────────┐
│ opt [user is premium] │
│ ┌─────────────────────────────────────────┤
│ │ applyPremiumDiscount() │
└───────┴─────────────────────────────────────────┘
┌─────────────────────────────────────────────────┐
│ loop [for each item in cart] │
│ ┌─────────────────────────────────────────┤
│ │ validateStock(item) │
│ │ calculatePrice(item) │
└───────┴─────────────────────────────────────────┘
Use Case Diagram (Bonus)
For understanding system scope:Copy
┌─────────────────────────────────┐
│ E-commerce System │
│ │
┌─────┐ │ ┌─────────────────┐ │
│ │ │ │ Browse Products │ │
│ User├──────────┼───>│ │ │
│ │ │ └─────────────────┘ │
└──┬──┘ │ │
│ │ ┌─────────────────┐ │
│ │ │ Add to Cart │ │
└─────────────┼───>│ │ │
│ └─────────────────┘ │
│ │ │
│ │ <<include>> │
│ ▼ │
┌─────┐ │ ┌─────────────────┐ │
│ │ │ │ Checkout │ │
│Admin├──────────┼───>│ │ │
│ │ │ └─────────────────┘ │
└─────┘ │ │ │
│ │ <<extend>> │
│ ▼ │
│ ┌─────────────────┐ │
│ │ Apply Coupon │ │
│ └─────────────────┘ │
└─────────────────────────────────┘
Interview Tips
Start Simple
Start Simple
Begin with core classes and relationships. Add details as you discuss with the interviewer.
Talk While Drawing
Talk While Drawing
Explain your thought process as you draw. This shows your reasoning skills.
Use Proper Notation
Use Proper Notation
Know the difference between composition (◆) and aggregation (◇). Interviewers notice!
Focus on Important Parts
Focus on Important Parts
You don’t need every getter/setter. Focus on key attributes and methods.
Practice Tip: Draw diagrams for common systems (Parking Lot, Library, etc.) until the notation becomes second nature.