bigonotes
CS ConceptsSOLID Principles

SOLID Overview

A quick map of the five SOLID principles: what each means, how to spot a violation, and where to learn more.

1 min readLast updated

SOLID is a set of 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 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 only 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.
Revision notes · 1 min

Core idea#

SOLID is a set of five design principles for object-oriented code. Each one is a disciplined use of encapsulation, abstraction, inheritance or polymorphism.

Key points#

  • Without SOLID, large codebases get hard to change, hard to extend and hard to maintain.
  • Symptoms: fixing one thing breaks another, every feature edits old code, and no class has a clear responsibility.
  • Together the principles make code easier to change, test and extend.

The five principles#

Principle One-line meaning OOP idea
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

Spot a violation#

Symptom Principle broken
"And" in the class description SRP
A new feature needs edits to existing code OCP
A child surprises or breaks callers of the parent LSP
A class implements methods only to raise or pass ISP
A class constructs its own collaborators DIP

Say it in an interview#

  • "SOLID is OOP done well: each principle is a disciplined use of one OOP idea."

Found a mistake? Email ask@bigonotes.com