SOLID is five design principles for object-oriented code. Without them, large codebases get hard to change (fixing one thing breaks another), hard to extend (every feature edits old code) and hard to maintain (no clear responsibilities). SOLID is really OOP done well: each principle is a disciplined use of encapsulation, abstraction, inheritance or polymorphism. This page is a quick map; each principle has its own lesson with examples.
The five principles at a glance#
Each letter names one principle, and each builds on an OOP idea you already know:
| Principle | One-line meaning | OOP idea behind it |
|---|---|---|
| Single Responsibility | One class, one reason to change | Encapsulation |
| Open/Closed | Extend behavior without modifying existing code | Abstraction + polymorphism |
| Liskov Substitution | A child can stand in for its parent | Correct inheritance |
| Interface Segregation | Don't force classes to implement unused methods | Correct abstraction |
| Dependency Inversion | Depend on abstractions; inject dependencies | Abstraction + polymorphism |
For an example that uses all five at once, see All five principles together in the DIP lesson.
Key takeaways#
- "And" in a class description: SRP is likely violated.
- Adding a feature requires editing existing code: OCP is violated.
- A child surprises or breaks callers of the parent: LSP is violated.
- A class implements methods just to raise or
pass: ISP is violated. - A class constructs its own collaborators: DIP is violated.
- Together they make code easier to change, test and extend.