Why SOLID matters in LLD
SOLID is not a vocabulary quiz — it is a set of pressure tests for class boundaries. In a 45-minute loop, interviewers watch whether your design survives a single new requirement without a cascade of edits. Each principle maps to a concrete question you should ask while drawing boxes.
| Principle | One-line test | Common LLD violation |
|---|---|---|
| Single Responsibility | One reason to change per class | OrderService also sends email and calculates tax |
| Open/Closed | Extend via new types, not edits | switch(vehicleType) in ParkingLot |
| Liskov Substitution | Subtypes honor the contract | ReadOnlyFile that throws on write() |
| Interface Segregation | Small, role-specific interfaces | Fat Repository with 12 methods, callers use 2 |
| Dependency Inversion | Depend on abstractions | PaymentProcessor constructs StripeClient directly |
Applying each principle under time pressure
SRP — split when a class mixes domain logic with infrastructure (e.g., Book shouldn't format receipts). OCP — identify the axis of change (pricing rules, vehicle types, notification channels) and put it behind an interface. LSP — if a subclass weakens preconditions or strengthens postconditions, callers break silently; prefer composition. ISP — in Java/C#, split Worker from Schedulable if only the scheduler needs schedule(). DIP — high-level modules (Checkout) receive PricingStrategy via constructor; they never new concrete strategies.
Quick violation → fix map
| You see… | Likely fix |
|---|---|
Growing switch on type | Extract Strategy or Factory |
| Subclass overrides half the parent | Replace with composition |
| Test needs 10 mocks to construct one class | DIP violation — inject interfaces |
| Interface with unused methods | Split per ISP |
Senior-level signal
Name the principle and the refactor: "This violates OCP because adding ElectricVehicle means editing allocateSpot() — I'd extract SpotAllocationStrategy and inject it." Interviewers score the diagnosis, not the acronym. Also flag when a principle conflicts with YAGNI: "I'd defer a plugin registry until we have a second payment provider."
Where this goes next
Composition vs Inheritance shows how to achieve OCP and LSP without deep inheritance trees — the mechanical follow-up once you've spotted a violation.
Further Reading
- Robert C. Martin — The Principles of OOD (original SOLID article series on butunclebob.com)Article30m
- Clean Code — Ch. 10: Classes (SRP in practice; classes should be small and single-purpose)Book25m
- Refactoring.Guru — SOLID principles (concise per-principle examples with diagrams)Reference25m
- Applying UML and Patterns (Larman) — Ch. 16–17: GRASP principles (Information Expert, Creator, Controller)Book35m
Practice Tasks (Optional)
Design or implement locally in any language — no autograding. Focus on class structure, extensibility, and being able to explain trade-offs out loud.
- Find a SOLID violation in existing code25m
Open any medium-sized class in a project you know (or a GitHub sample). Identify one SRP or OCP violation and sketch how you'd split or extend it without modifying existing callers.