AI InterviewSearch…Search problems, topics, or pages…Ctrl KGet started
Skip to content
LLD notes

Low-Level Design · Note 3 of 9

Design Patterns in LLD

Intermediate · 6 min read · updated 14 November 2026

Quick answer

Which design patterns are used most in low-level design interviews?

Strategy, Observer, State, Factory, Singleton and Decorator cover most low-level design rounds. Strategy swaps a rule such as pricing, Observer notifies displays of a change, State models a vending machine or an order, Factory creates the right subclass from a type, Singleton guards one shared registry, and Decorator stacks optional add-ons. Use each only where a requirement is likely to change.

On this page
  1. Strategy: rules that vary
  2. Observer: tell everyone who cares
  3. State: behaviour follows status
  4. Factory: one place to create
  5. Decorator: stackable add-ons
  6. Singleton: exactly one
  7. Choosing one
  8. Interview questions
  9. Common questions

Patterns are named answers to changes you can predict. In an LLD round, reach for one when a requirement says "rules vary", "others must be told" or "behaviour depends on status".

The intent and structure of each are in Design Patterns; this note is where they land in a design.

Strategy: rules that vary

  • Use: pricing, discount, spot allocation, payment method.
  • A context holds the rule behind an interface and can swap it at run time.
  • A new rule is a new class: the open/closed principle from SOLID.
Strategy: a swappable pricing rule for a parking lot
a 3-hour stay

A parking lot must price a stay, and the pricing rules will change. FeeCalculator keeps the rule in a field typed by an interface, never by a class.

0:01 / 0:12Step 1 of 4
Transcript · 4 steps

Observer: tell everyone who cares

  • Use: display boards, notifications, stock alerts, auction bids.
  • The subject keeps a list of observers and calls update on each.
  • The subject never knows what an observer does with the news.
Observer: the lot tells every display when a spot frees up
2 free spots; park, park, leave

The board at the entrance and the mobile app both need the free-spot count. They subscribe to the lot, which keeps them in a list typed by an Observer interface.

0:01 / 0:13Step 1 of 4
Transcript · 4 steps

State: behaviour follows status

  • Use: vending machine, ATM, elevator, order lifecycle, traffic light.
  • One class per state; the machine delegates every call to its current state.
  • Each state decides the next state; no if (status == …) chains.
State: a vending machine's behaviour follows its state
events: select, insertCoin, select, dispense

A vending machine behaves differently in each state. With the State pattern each state is a class implementing the same methods, and the machine delegates to its current state object.

0:01 / 0:16Step 1 of 5
Transcript · 5 steps

Factory: one place to create

  • Use: vehicles from a type, payment methods, notification channels.
  • Callers ask for a type and get back the interface.
  • A new subclass changes the factory only.
Factory: one place decides which vehicle class to create
create car, bike, truck

The entry gate gets a type name from a sensor or a form and needs a vehicle object. It asks VehicleFactory instead of calling new on a concrete class.

0:01 / 0:12Step 1 of 4
Transcript · 4 steps

Decorator: stackable add-ons

  • Use: ticket add-ons, pizza toppings, coffee extras, logging around a service.
  • Each decorator is the same interface and wraps one inner object.
  • Any combination at run time, without a subclass per combination.
Decorator: add-ons wrap a parking pass
new Valet(new EvCharging(new BasicPass()))

A BasicPass costs 60. Customers can add EV charging, valet, or both, and a subclass per combination would explode.

0:01 / 0:11Step 1 of 4
Transcript · 4 steps

Singleton: exactly one

  • Use: an ID generator, a configuration, a registry that must be unique.
  • Private constructor and one access point.
  • Prefer passing the instance in; a global is hard to test and hides dependencies.

Choosing one

Signal in the requirementPattern
"different ways to compute X"Strategy
"notify", "subscribe", "alert"Observer
"in state A it does X, in B it does Y"State
"create a … based on type"Factory
"optional extras in any combination"Decorator
"only one … in the system"Singleton

Interview questions

  • Strategy or State for an order that moves from placed to shipped? State: the order changes its own status and each status allows different actions.
  • How does Observer avoid tight coupling? The subject depends only on the observer interface.
  • What does a factory buy you? Callers never name concrete classes, so adding one touches one place.
  • When not to use a pattern? When nothing in the requirements is going to change there.

Next: Design an LRU Cache · Before this: UML Class Diagrams for LLD Interviews

Common questions

How do I know which design pattern to use in an LLD round?

Look for the part of the requirement that will change or vary. A rule with several versions points to Strategy, many parties reacting to one event to Observer, behaviour that depends on a status to State, and creating one of several subclasses from input to Factory.

What is the difference between Strategy and State?

Both put behaviour behind an interface. In Strategy the client picks the object and the strategies know nothing of each other. In State the object changes its own state as events happen, and each state usually decides which state comes next.

Should I use Singleton for the parking lot class?

Only if the problem says there is exactly one lot per process, and even then pass the instance to the classes that need it. Singleton is global state, which hides dependencies and makes tests share data, so many interviewers prefer you to justify it.

Is it bad to use too many patterns in an LLD interview?

Yes. A pattern adds classes and indirection, so each one should answer a change you can name from the requirements. Interviewers mark down a design that wraps every class in a factory or interface for no stated reason.

When is Decorator better than inheritance?

When features combine freely. With three optional add-ons, subclasses would need one class per combination, while decorators wrap one object in any number of add-ons in any order at run time.

Design Patterns for LLD Interviews, Applied

The six design patterns LLD rounds use most, each tied to a real use: Strategy pricing, Observer displays, State machines, Factory, Singleton, Decorator.

  • Subject: Low-Level Design
  • Level: Intermediate
  • Reading time: 6 min
  • Updated: 2026-11-14

Which design patterns are used most in low-level design interviews?

Strategy, Observer, State, Factory, Singleton and Decorator cover most low-level design rounds. Strategy swaps a rule such as pricing, Observer notifies displays of a change, State models a vending machine or an order, Factory creates the right subclass from a type, Singleton guards one shared registry, and Decorator stacks optional add-ons. Use each only where a requirement is likely to change.

Patterns are named answers to changes you can predict. In an LLD round, reach for one when a requirement says "rules vary", "others must be told" or "behaviour depends on status".

The intent and structure of each are in Design Patterns; this note is where they land in a design.

Strategy: rules that vary

  • Use: pricing, discount, spot allocation, payment method.
  • A context holds the rule behind an interface and can swap it at run time.
  • A new rule is a new class: the open/closed principle from SOLID.
FeeCalculator- rule: PricingStrategy+ setRule(r)+ fee(hours): int«interface»PricingStrategy+ fee(hours): intruleHourlyPricing+ fee(hours)fee(3) = 60FlatPricing+ fee(hours)fee(3) = 100EventPricing+ fee(hours)fee(3) = 120
Strategy: a swappable pricing rule for a parking lot. Example: a 3-hour stay
  1. A parking lot must price a stay, and the pricing rules will change. FeeCalculator keeps the rule in a field typed by an interface, never by a class.
  2. HourlyPricing implements the interface: 20 an hour, so a 3-hour stay costs 60.
  3. FlatPricing is a second strategy: 100 a day, any length, so the same stay costs 100. setRule swaps it in at run time.
  4. A new rule for event days, double the hourly rate (120 for 3 hours), is one new class. FeeCalculator is not edited: open for extension, closed for modification.

Observer: tell everyone who cares

  • Use: display boards, notifications, stock alerts, auction bids.
  • The subject keeps a list of observers and calls update on each.
  • The subject never knows what an observer does with the news.
Gatelot: ParkingLotboard: Displayapp: MobileAppleave()update(1)update(1)free = 1Free: 11 spot free
Observer: the lot tells every display when a spot frees up. Example: 2 free spots; park, park, leave
  1. The board at the entrance and the mobile app both need the free-spot count. They subscribe to the lot, which keeps them in a list typed by an Observer interface.
  2. A car parks: free drops to 1 and the lot calls update on every subscriber in order. It does not know what a board or an app does with the number.
  3. The last spot is taken: update(0). The board decides on its own to show FULL and the app sends a push; the lot's code is the same.
  4. A car leaves and free goes back to 1. Adding an SMS alert later means one new observer class and one subscribe call.

State: behaviour follows status

  • Use: vending machine, ATM, elevator, order lifecycle, traffic light.
  • One class per state; the machine delegates every call to its current state.
  • Each state decides the next state; no if (status == …) chains.
insertCoinrefundselectdispenseIdleHasCoinDispensingstate = Idle
State: a vending machine's behaviour follows its state. Example: events: select, insertCoin, select, dispense
  1. A vending machine behaves differently in each state. With the State pattern each state is a class implementing the same methods, and the machine delegates to its current state object.
  2. select() arrives in Idle. The Idle state's select just answers "insert a coin first": no if-else on a status field anywhere.
  3. insertCoin() in Idle: the Idle state object handles it and switches the machine to a HasCoin state. The state, not the caller, picks the next state.
  4. select() in HasCoin: the item is chosen and the machine moves to Dispensing, where coins are no longer accepted.
  5. dispense() drops the item and returns to Idle, ready for the next customer. Adding a SoldOut state means one new class.

Factory: one place to create

  • Use: vehicles from a type, payment methods, notification channels.
  • Callers ask for a type and get back the interface.
  • A new subclass changes the factory only.
EntryGate+ admit(type)VehicleFactory+ create(type): Vehicle«abstract»Vehicle+ spotSize(): SizecreatesCar+ spotSize()Bike+ spotSize()Truck+ spotSize()create("car") → Carcreate("bike") → Bikecreate("truck") → Truck
Factory: one place decides which vehicle class to create. Example: create car, bike, truck
  1. The entry gate gets a type name from a sensor or a form and needs a vehicle object. It asks VehicleFactory instead of calling new on a concrete class.
  2. create("car") returns a Car, typed as Vehicle. The gate only ever sees Vehicle and asks it for its spot size: compact.
  3. create("bike") returns a Bike, which needs a small spot. The choice of class lives in one place, the factory.
  4. Adding Trucks (large spots) touched only the factory's table. The gate, the lot and the spot-finding code did not change.

Decorator: stackable add-ons

  • Use: ticket add-ons, pizza toppings, coffee extras, logging around a service.
  • Each decorator is the same interface and wraps one inner object.
  • Any combination at run time, without a subclass per combination.
Valet +50EvCharging +40BasicPass +60cost() = 60+ 40 = 100+ 50 = 150
Decorator: add-ons wrap a parking pass. Example: new Valet(new EvCharging(new BasicPass()))
  1. A BasicPass costs 60. Customers can add EV charging, valet, or both, and a subclass per combination would explode.
  2. EvCharging wraps the pass: it is also a Pass, holds the inner one, and its cost() is the inner cost plus 40, so 100.
  3. Valet wraps that in turn. The caller still holds one Pass and calls one cost(); it cannot tell how many wrappers there are.
  4. cost() runs from the outside in and the total builds on the way back out: 60, then 100, then 150. Any order or mix of add-ons works.

Singleton: exactly one

  • Use: an ID generator, a configuration, a registry that must be unique.
  • Private constructor and one access point.
  • Prefer passing the instance in; a global is hard to test and hides dependencies.

Choosing one

Signal in the requirementPattern
"different ways to compute X"Strategy
"notify", "subscribe", "alert"Observer
"in state A it does X, in B it does Y"State
"create a … based on type"Factory
"optional extras in any combination"Decorator
"only one … in the system"Singleton

Interview questions

  • Strategy or State for an order that moves from placed to shipped? State: the order changes its own status and each status allows different actions.
  • How does Observer avoid tight coupling? The subject depends only on the observer interface.
  • What does a factory buy you? Callers never name concrete classes, so adding one touches one place.
  • When not to use a pattern? When nothing in the requirements is going to change there.

Next: Design an LRU Cache · Before this: UML Class Diagrams for LLD Interviews

Common questions

How do I know which design pattern to use in an LLD round?

Look for the part of the requirement that will change or vary. A rule with several versions points to Strategy, many parties reacting to one event to Observer, behaviour that depends on a status to State, and creating one of several subclasses from input to Factory.

What is the difference between Strategy and State?

Both put behaviour behind an interface. In Strategy the client picks the object and the strategies know nothing of each other. In State the object changes its own state as events happen, and each state usually decides which state comes next.

Should I use Singleton for the parking lot class?

Only if the problem says there is exactly one lot per process, and even then pass the instance to the classes that need it. Singleton is global state, which hides dependencies and makes tests share data, so many interviewers prefer you to justify it.

Is it bad to use too many patterns in an LLD interview?

Yes. A pattern adds classes and indirection, so each one should answer a change you can name from the requirements. Interviewers mark down a design that wraps every class in a factory or interface for no stated reason.

When is Decorator better than inheritance?

When features combine freely. With three optional add-ons, subclasses would need one class per combination, while decorators wrap one object in any number of add-ons in any order at run time.

← UML Class Diagrams for LLD Interviews · Design an LRU Cache →