Chapter 20
Patterns frequency map across the 15 problems
Notice how patterns recur:
| Pattern | Problems where it appears |
|---|---|
| Strategy | Parking Lot (allocation, payment, pricing); Elevator (dispatch); ATM (transaction types); Splitwise (split types); Logger (appender); Rate Limiter (algorithm) |
| State | Elevator; ATM; Vending Machine; BookMyShow (booking lifecycle) |
| Observer | Library (notify reservation holder); Pub-Sub (core); BookMyShow (notification on booking) |
| Factory | Parking Lot (vehicles, spots); Vending Machine (items); File System (nodes) |
| Composite | File System; Logger (multiple appenders) |
| Decorator | Logger (AsyncAppender wraps); Coffee customization |
| Command | ATM (transactions); Splitwise (expense actions) |
| Singleton | Logger factory; thread pool; rate limiter (often) |
| Chain of Responsibility | Logger (level filtering) |
| Template Method | Game framework (Chess/TicTacToe shared structure) |
Strategy is the most useful pattern in LLD — it shows up almost everywhere. State is the second-most common, anywhere a system has explicit phases. Observer covers most "notify many" cases. The rest are domain-specific.
The insight: recognise the pattern, then implement it; don't reach for a pattern just because you know it. Each pattern solves a specific problem. Use it when that problem appears; don't force-fit.