← All items

SOLID Principles

Five design principles that guide good OOD — Single Responsibility, Open-Closed, Liskov Substitution, Interface Segregation, Dependency Inversion.

5 items 3 Foundational 2 Intermediate

SOLID is the most-quoted acronym in object-oriented design and the most-misunderstood. Each letter is a constraint on how classes relate; together they're a recipe for code that survives changing requirements without rewrites.

In an interview the principles function as a critique vocabulary. When you point at a class diagram and say 'this violates SRP because X and Y change for different reasons', or 'this couples high-level policy to low-level detail — let's invert the dependency', you're showing the interviewer that you can reason about design, not just produce one.

Key concepts

  • SRP — one reason to change per class
  • OCP — extend behaviour without modifying existing code (polymorphism is the lever)
  • LSP — subtypes must honour the contract of their base type, not just its signatures
  • ISP — many small interfaces beat one fat interface
  • DIP — high-level modules depend on abstractions, not concretions (and so do the abstractions)

Reference template

// SOLID critique on any class diagram
1. Does each class have ONE reason to change?  (SRP)
2. Can I add a new behaviour by adding code, not editing? (OCP)
3. Can every subclass stand in for its parent without breaking callers? (LSP)
4. Does any class implement methods it doesn't use? (ISP)
5. Do high-level modules import low-level modules directly? (DIP — bad sign)

Adapt to your problem; the structure is the load-bearing part.

Common pitfalls

  • Treating SOLID as five independent rules — they reinforce each other; violations cluster
  • Citing SRP without naming the two reasons to change — the diagnosis must be specific
  • Inverting dependencies for the sake of it — DIP costs interface ceremony; spend it where you're likely to need substitution
  • Forgetting LSP applies to BEHAVIOUR — not just to type signatures

Related topics

Items (5)

Search ESC

Keyboard shortcuts

Shortcuts are disabled while typing in inputs.