Most codebases do not rot because the developers were careless. They rot because a small decision made in month two, like one class that both validates an order and emails the customer, makes every later change cost three times what it should. The five SOLID principles are the cheapest known defence against that drift. They are not rules to recite in an interview. They are tests you can run on your own code before the cost of change becomes permanent.

Key takeaways

  • SOLID is five tests for one question: when a requirement changes, how many files do I open?
  • Single Responsibility means one reason to change, and the reasons come from the people who ask for changes.
  • Apply Open/Closed and Dependency Inversion only where variation is real: money, notifications, storage, file formats.
  • An interface with one implementation and no test double is decoration, not design.
  • Duplicating code twice costs less than one wrong abstraction.
Working definition

SOLID is a mnemonic acronym for five object-oriented design principles meant to make source code easier to understand, change and maintain: Single responsibility, Open/closed, Liskov substitution, Interface segregation and Dependency inversion.

Why SOLID, and why now

The acronym was coined by Michael Feathers around Robert C. Martin's principles, and it has survived three decades of framework churn because it answers one question: when a requirement changes, how many files do I have to open? A design that keeps that number small is a design that keeps a team fast. Everything below is measured against that single yardstick.

Screenshot of the Wikipedia article on SOLID showing the five principles
Figure 1 — Wikipedia’s SOLID article credits Robert C. Martin with the principles (2000) and Michael Feathers with the acronym (around 2004). Screenshot: en.wikipedia.org, December 2026.

S — Single Responsibility: one reason to change

The principle is not "a class does one thing". It is "a class has one reason to change", and the reasons come from the people who ask for changes. Finance asks for a new tax rule. Marketing asks for a new email template. Operations asks for a different database. Those are three different requesters, so they should not touch the same file.

Here is the shape this usually takes in a real project:

// Before: three requesters, one class, three reasons to change
class OrderService {
  place(order) {
    if (!order.items.length) throw new Error('empty');
    if (order.total < 0) throw new Error('invalid total');
    db.query('INSERT INTO orders ...', order);
    mailer.send(order.email, 'Your order is confirmed');
  }
}

The refactor is not "split the method". It is "move each responsibility behind a name that says who owns it":

class OrderValidator { validate(order) { /* rules only */ } }
class OrderRepository { save(order) { /* persistence only */ } }
class OrderNotifier { confirm(order) { /* messaging only */ } }

class PlaceOrder {
  constructor(validator, repository, notifier) { ... }
  run(order) {
    this.validator.validate(order);
    this.repository.save(order);
    this.notifier.confirm(order);
  }
}

Nothing clever happened. The win is that a tax change now touches the validator, an email redesign touches the notifier, and a database migration touches the repository. Three teams, three files, no merge conflicts. Notice that PlaceOrder itself became a thin coordinator: that is the useful second-order effect of applying this principle properly.

Diagram splitting OrderService into OrderValidator, OrderRepository and OrderNotifier by owner
Figure 2 — The OrderService refactor: each class now has one owner. Diagram: AIGS, December 2026.

O — Open/Closed: extend without editing

Open for extension, closed for modification. In practice this means: when the third payment method arrives, you should add a file, not edit a growing if chain in a file that already works.

interface PaymentMethod { charge(amount: Money): Result; }

class CardPayment implements PaymentMethod { ... }
class WalletPayment implements PaymentMethod { ... }
class BankTransfer implements PaymentMethod { ... }

function checkout(method: PaymentMethod, amount: Money) {
  return method.charge(amount);
}

The honest caveat: you cannot make everything extensible, and trying is how teams end up with twenty interfaces nobody implements twice. Apply it where you already know variation is coming, which is usually money, notifications, storage and file formats. For everything else, wait for the second real case. Duplicating code twice is cheaper than a wrong abstraction.

L — Liskov Substitution: a subtype must keep its promises

If code works with a type, it must keep working with any subtype, without the caller checking which one it got. The classic violation is a subclass that throws on a method it inherited. The realistic violation is subtler: a "read-only" repository that extends a writable one and silently ignores writes.

class Rectangle { setWidth(w) {...} setHeight(h) {...} area() {...} }
class Square extends Rectangle {
  setWidth(w) { this.w = w; this.h = w; }   // silently changes height too
}
// A function written for Rectangle now returns the wrong area for Square.

The fix is not a comment. Either model the shapes separately, or make the contract express what is true: Shape with area() only. A good test: if a subtype needs a guard clause in the caller to be safe, the hierarchy is wrong.

A subtype that needs a guard clause in the caller is a lie in the hierarchy.

I — Interface Segregation: no client should depend on what it does not use

A fat interface forces every implementer to stub out methods it will never need, and every caller to depend on a surface it does not control. Split by client, not by convenience.

// Too much: a report generator only needs to read
interface DocumentStore {
  read(id); write(id, doc); delete(id); backup(); restore(snapshot);
}

// Split by what each client actually does
interface DocumentReader { read(id); }
interface DocumentWriter { write(id, doc); }

This principle is also the cure for mock-heavy tests. If a test needs eleven mocks to instantiate a class, the class depends on eleven things it does not need, and the interface is telling you so.

D — Dependency Inversion: depend on behaviour, not on a vendor

High-level policy should not import the low-level detail. The high-level code declares the interface it needs; the detail implements it. That single inversion is what makes a database swappable and a test suite fast.

// Policy declares the need
interface UserStore { find(id): User | null; }

class RegisterUser {
  constructor(private store: UserStore, private hasher: Hasher) {}
  run(email, password) {
    if (this.store.find(email)) throw new Error('exists');
    this.store.save({ email, hash: this.hasher.hash(password) });
  }
}

// Detail implements it: MySQL, SQLite, or an in-memory fake in tests
class SqliteUserStore implements UserStore { ... }

This is the principle most often applied backwards. Creating an interface for a class that will only ever have one implementation adds indirection without buying anything. The test is whether something else plugs in: a test double, a second database, a second payment provider. If nothing else ever plugs in, the interface is decoration.

Two columns listing the question each SOLID principle asks and the code smell that signals a violation
Figure 3 — One question and one smell per principle. Diagram: AIGS, December 2026.

Where SOLID goes wrong

Tip

Before adding an interface, name the second implementation: a test double, another database, another provider. If you cannot, wait.

Three failure modes show up in almost every codebase that adopted the principles too enthusiastically.

  • One-to-one interfaces. An interface for every class, implemented once, never mocked. This doubles the file count and hides the real seams.
  • Premature abstraction. Designing for a variation that never arrives. The cost is paid now, the benefit never is.
  • Coordinator sprawl. Splitting so aggressively that one business action passes through six classes, and no single file tells you what the system does. Keep the coordinator readable and name it after the use case.

The balance is simple to state and hard to keep: apply a principle when you can point at the concrete change it makes cheap, and skip it when you cannot. SOLID is a set of tools for reducing the cost of change, not a measure of how seriously a team takes software design.

“SOLID means every class needs an interface.”

An interface with one implementation that is never mocked only adds files. Add one where something else will plug in.

“Single Responsibility means a class does one thing.”

It means one reason to change, and reasons come from the people who request changes.

“More splitting is always better.”

Six classes for one business action hides what the system does. Keep the coordinator readable and named after the use case.

“SOLID is only for large enterprise code.”

The five questions cost nothing to ask on a small project, and they are cheapest early.

A checklist you can run today

  • Open your largest class. List the people who could ask for a change to it. More than one team means split it.
  • Find the longest if or switch on a type code. That is a missing interface, and the next variant will be added by editing working code.
  • Look for a subclass that throws NotSupported or ignores an inherited method. The hierarchy is lying to its callers.
  • Count the mocks in your slowest test. Each one is a dependency you did not need.
  • Search for new Database() inside business logic. That is a vendor decision buried where it cannot be replaced.

If you want a second pair of eyes on a codebase that has grown past this point, our systems analysis service starts with exactly this audit: dependency mapping, responsibility boundaries, and a refactor order that keeps the product shipping while it happens. For the small daily work, the regex tester and the word counter are the two tools our own team opens most while cleaning up code and documentation.

Screenshot of the AIGS regex tester highlighting two email matches
Figure 4 — Our own regex tester, one of the tools the team opens most while cleaning up code. Screenshot: ai-gs.net, December 2026.
Further reading

The Wikipedia article on SOLID lists the original sources, and Martin Fowler’s bliki carries the counter-arguments on abstraction.

Part 1 of 14 — Engineering Foundations series

This series follows the order real work follows: write clean code, structure it, model it, specify it, store it, expose it, prove it, scale it, then choose the shape of the whole system. Next up: creational design patterns, where Factory and Builder solve the problem SOLID leaves open, creating objects without hard-coding their class.

Browse the rest of the series on the AIGS blog, or see how we apply it in client work on the services page.