OOD & LLD Reference/OOD Foundations

SOLID Principles

Single Responsibility, Open/Closed, Liskov Substitution, Interface Segregation, Dependency Inversion — what each means in practice and how to spot violations in a whiteboard design.

2/5Overview: 25m

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.

PrincipleOne-line testCommon LLD violation
Single ResponsibilityOne reason to change per classOrderService also sends email and calculates tax
Open/ClosedExtend via new types, not editsswitch(vehicleType) in ParkingLot
Liskov SubstitutionSubtypes honor the contractReadOnlyFile that throws on write()
Interface SegregationSmall, role-specific interfacesFat Repository with 12 methods, callers use 2
Dependency InversionDepend on abstractionsPaymentProcessor 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 typeExtract Strategy or Factory
Subclass overrides half the parentReplace with composition
Test needs 10 mocks to construct one classDIP violation — inject interfaces
Interface with unused methodsSplit 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

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 code

    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.

    25m