SOLID Principles

Glossary

SOLID is a set of five object-oriented design principles, popularized by Robert C. Martin, for structuring code so that it tolerates change without cascading edits. Each principle attacks a specific way a design goes rigid: a class that changes for too many reasons, a module you cannot extend without editing, a subtype that breaks its callers, an interface that forces dead code on its implementers, or a high-level policy welded to a low-level detail.

The payoff is practical. Code that follows SOLID localizes change (an edit stays in one place), supports substitution (you can swap an implementation without the caller noticing), and is testable almost for free – the same seams that let you inject a real collaborator let a test inject a test double via dependency injection.

The five principles are:

They are not five unrelated rules – they reinforce each other. SRP keeps units small enough to have a clear contract. ISP keeps the abstractions those units depend on narrow, and DIP points that dependency at an abstraction rather than a concrete type – together they make a unit open for extension (OCP), because a new implementation plugs in without editing the consumer. LSP is what makes that substitution safe: extension only works if every implementation actually honors the abstraction’s contract.

flowchart TD
  SRP["Single Responsibility\n(small, focused units)"]
  ISP["Interface Segregation\n(narrow abstractions)"]
  DIP["Dependency Inversion\n(depend on abstractions)"]
  LSP["Liskov Substitution\n(honor the contract)"]
  OCP["Open/Closed\n(extend without editing)"]

  SRP --> ISP
  ISP --> DIP
  DIP --> OCP
  LSP --> OCP

References

  • Design Principles and Design Patterns – the paper that collected these principles; the origin of the SOLID grouping.
  • SOLID – overview of the acronym and each principle with further references.
  • Solid Relevance – Martin’s retrospective on what the principles are actually about and where they still apply.