System Atlas
the atlas

The SOLID principles

Five object-oriented design rules that keep code flexible instead of fragile.

the gist

SOLID is five principles for designing classes that are easy to maintain and extend: Single Responsibility (one reason to change), Open/Closed (open to extension, closed to modification), Liskov Substitution (subtypes must be substitutable for their base), Interface Segregation (many small interfaces over one fat one), and Dependency Inversion (depend on abstractions, not concretions). Together they reduce coupling and make change safe.

ANALOGY // Like designing appliances around standard sockets: each appliance does one job, you add new ones without rewiring the house, any plug fits any socket, and everything depends on the socket's shape, not a specific brand.
living diagram01 / 05
Five principles for maintainable object-oriented design
01
S — Single Responsibility
one job, one reason to change — a change to one concern can't break another
02
O — Open/Closed
open to extension, closed to modification — add code, don't edit tested code
03
L — Liskov Substitution
subtypes must be usable anywhere the base type is, honoring its contract
04
I — Interface Segregation
many small focused interfaces beat one fat one — depend only on what you use
05
D — Dependency Inversion
depend on abstractions, not concretions — inject details into policy
01

Single Responsibility

A class should have exactly one reason to change, meaning it owns a single responsibility. When a class handles several concerns — say business logic, persistence and formatting — a change to any one risks breaking the others and the class becomes a tangle. Splitting responsibilities keeps each class small, focused and safe to modify in isolation.

02

Open/Closed

Software entities should be open for extension but closed for modification: you add new behavior by writing new code, not by editing code that already works and is already tested. Achieved through abstractions like interfaces and polymorphism, it means adding a new payment type or shape doesn't force you to reopen and risk breaking the existing cases.

03

Liskov Substitution

Objects of a subclass must be substitutable for objects of their base class without breaking the program's correctness. A subtype has to honor the contract of its parent — same expectations, no surprising exceptions or weakened guarantees. The classic violation is a Square subclassing Rectangle: setting width and height independently breaks code written against a rectangle.

04

Interface Segregation

Clients should not be forced to depend on methods they do not use, so favor many small, role-specific interfaces over one fat catch-all. A giant interface forces implementers to stub methods irrelevant to them and couples callers to things they never touch. Splitting it means each class implements only what it genuinely needs.

05

Dependency Inversion

High-level modules should not depend on low-level modules; both should depend on abstractions. Instead of business logic directly newing up a concrete MySQL class, it depends on a Database interface, and the concrete implementation is injected. This inverts the usual direction of dependency so details plug into policy, making code testable and swappable.

the full picture
01

What SOLID is and why it exists

SOLID is an acronym for five object-oriented design principles, collected and popularized by Robert C. Martin, that together guide you toward code which is easy to understand, maintain, and extend. Each letter names a principle — Single Responsibility, Open/Closed, Liskov Substitution, Interface Segregation, and Dependency Inversion — and each attacks a different way that class design tends to rot over time.

The underlying enemy they all fight is coupling: the degree to which one part of a system is entangled with another. Highly coupled code is fragile — a change in one place ripples into unexpected breakages elsewhere — and rigid, because you cannot modify or reuse a piece without dragging its dependencies along. SOLID's collective goal is low coupling and high cohesion: each unit does one clear thing (cohesion) and connects to others only through stable abstractions (low coupling). When code follows these principles, change stays local and predictable; when it violates them, small edits become dangerous. They are guidelines, not laws — but internalizing them is much of what separates fragile code from adaptable code.

02

Single Responsibility and Open/Closed

The Single Responsibility Principle (SRP) states that a class should have only one reason to change — that is, it should own a single, well-defined responsibility. A class that mixes concerns, say computing an invoice, saving it to the database, and formatting it as a PDF, is fragile because a change to the report format can break the persistence logic, and it is hard to reuse any one behavior on its own. Splitting those into focused classes means each has one job, one reason to change, and can be understood and modified in isolation.

The Open/Closed Principle (OCP) states that software entities should be *open for extension but closed for modification*. You should be able to add new behavior without editing existing, working, already-tested code. The mechanism is abstraction: if your code depends on a Shape interface and calls area(), you can add a new Triangle by writing a new class, not by reopening a sprawling if (type == ...) switch and risking the cases that already work. Closed-to-modification protects what already works; open-to-extension lets the system grow. This is the principle that keeps a codebase from becoming a minefield where every new feature threatens the old ones.

03

Liskov Substitution

The Liskov Substitution Principle (LSP), named for Barbara Liskov, states that objects of a subclass must be substitutable for objects of their superclass without altering the correctness of the program. In other words, if code works with a base type, it must continue to work when handed any subtype — no surprises, no weakened guarantees, no unexpected exceptions.

The famous illustration is the Rectangle/Square problem. Mathematically a square *is* a rectangle, so it is tempting to make Square extend Rectangle. But a Rectangle lets you set width and height independently, and code may rely on that — set width to 5, height to 4, expect area 20. A Square that forces width and height equal breaks that expectation: setting the width silently changes the height. Code written against Rectangle now misbehaves when given a Square, violating LSP. The lesson is that inheritance must model true behavioral substitutability, not just a real-world "is-a" relationship. When a subtype cannot honor its parent's contract, inheritance is the wrong tool — favor composition instead. LSP is what makes polymorphism, and therefore the Open/Closed principle, actually safe.

04

Interface Segregation and Dependency Inversion

The Interface Segregation Principle (ISP) states that no client should be forced to depend on methods it does not use. Prefer many small, role-specific interfaces over one large, general-purpose one. Consider a fat Worker interface with work() and eat(): a RobotWorker that implements it is forced to provide a meaningless eat(). Splitting into Workable and Feedable lets each class implement only what genuinely applies. Fat interfaces couple clients to methods they never call, so a change to an irrelevant method still forces them to recompile or adapt; segregated interfaces keep those dependencies minimal and honest.

The Dependency Inversion Principle (DIP) states that high-level modules should not depend on low-level modules — both should depend on abstractions — and that abstractions should not depend on details. Rather than your business logic directly instantiating a concrete MySQLDatabase, it depends on a Database interface, and the concrete implementation is *injected* from outside (this is the idea behind dependency injection). This inverts the traditional flow of dependency: instead of policy depending on details, details depend on policy through a shared abstraction. The payoff is enormous — you can swap MySQL for Postgres, or substitute a fake database in tests, without touching the business logic at all. DIP is the principle that makes code testable, modular, and resistant to churn in its low-level components.

05

How SOLID fits together in practice

The five principles are not independent rules to tick off; they reinforce one another toward the same end. Single Responsibility gives you small, cohesive classes. Interface Segregation gives those classes lean, focused contracts. Dependency Inversion wires them together through abstractions rather than concrete types. Open/Closed lets the whole thing grow by addition rather than edit, and Liskov Substitution is what makes the polymorphism underpinning Open/Closed trustworthy. Applied together, they yield a system of loosely coupled, highly cohesive parts that you can change one piece at a time.

A word of balance, though: SOLID can be over-applied. Chasing the principles too zealously produces its own problem — a fog of tiny classes and interfaces so numerous that the code becomes hard to follow, an over-engineering trap just as real as a tangled monolith. The principles are tools for managing *change*, so their value is highest in code that will genuinely evolve and be maintained by a team over time, and lower in a small script that will never grow. Use them to guide design decisions and to diagnose why a piece of code feels fragile or hard to test — not as a rigid checklist to satisfy for its own sake. Good judgment about when a principle earns its complexity is itself part of mastering them.

what to remember
01

S — Single Responsibility: a class should have one job and therefore one reason to change.

02

O — Open/Closed: you should extend behavior by adding code, not by modifying existing, tested code.

03

L — Liskov Substitution: any subclass must be usable anywhere its parent is, without surprises.

04

I — Interface Segregation: prefer several small, focused interfaces to one large general-purpose one.

05

D — Dependency Inversion: high-level code and low-level code should both depend on abstractions.

06

The payoff is lower coupling and higher cohesion, so changes stay local and don't ripple outward.

check yourself

Quick quiz

Q1

What does the Open/Closed principle recommend?

Q2

Dependency Inversion says high-level modules should depend on…

follow the thread