SOLID Principles
Five design principles that guide good OOD — Single Responsibility, Open-Closed, Liskov Substitution, Interface Segregation, Dependency Inversion.
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)
- Single Responsibility Principle (SRP)
A class should have one and only one reason to change. The smell, the refactor, the cost of misapplying it.
Concept Foundational - Open Closed Principle (OCP)
Open for extension, closed for modification. How polymorphism and strategy patterns let you add behaviour without editing existing code.
Concept Foundational - Liskov Substitution Principle (LSP)
Subtypes must be substitutable for their base types. The square-vs-rectangle parable and what it actually teaches.
Concept Intermediate - Interface Segregation Principle (ISP)
No client should be forced to depend on methods it doesn't use. The case for many small interfaces over one fat one.
Concept Foundational - Dependency Inversion Principle (DIP)
Depend on abstractions, not concretions. Where DIP, IoC, and constructor injection are the same idea wearing three names.
Concept Intermediate