Part 4 of 10 · How we build

SOLID: which principles still pay off?

Single responsibility and dependency inversion pay off in almost every codebase. Open/closed, Liskov and interface segregation matter mostly at boundaries where implementations vary. What each principle protects against, and when it turns into over-engineering.

Ancient brick ruins with solid foundations in a grassy clearing among trees

Short answer: the verdict, as the cases below will show: use SOLID as a set of questions to ask at boundaries, not as rules to apply to every class.

  • Most useful everywhere: single responsibility (one reason to change) and dependency inversion (core logic doesn’t depend on the database or a vendor SDK).
  • Useful at real extension points: open/closed, Liskov substitution and interface segregation, where you actually have several implementations.
  • Over-engineering looks like: an interface for every class, factories for everything, and code you can’t follow without a debugger.

The case usually opens the same way: a codebase where a simple change means walking through four interfaces and a factory, and someone says “but it’s SOLID”. Is the principle guilty, or the way it was applied? I have a soft spot for SOLID. Robert C. Martin gathered these ideas together, and each one captures a real lesson someone learned the hard way; Barbara Liskov’s substitution principle in particular is a remarkably precise idea about what it means to keep a promise. The trick, and the mystery, is knowing where the lessons apply.

Case file

The case A simple change means walking through four interfaces and a factory: “but it’s SOLID”
Suspects SOLID itself, the way it was applied
Culprit Principles applied everywhere instead of at boundaries: an interface for every class
The fix Use SOLID as questions at real extension points; single responsibility and dependency inversion almost everywhere
Evidence The blogging platform I run: seven email implementations behind one Send method

The five, briefly #

Principle Plain meaning Protects against Over-applied, it becomes
Single responsibility A module has one reason to change One change breaking something unrelated Dozens of one-method classes
Open/closed Add new behaviour without editing existing, working code Regressions every time a variant is added Plugin systems for things that never get a second variant
Liskov substitution Any implementation can stand in for the interface without surprises Callers that special-case implementations Rarely over-applied; mostly ignored
Interface segregation Small interfaces that callers actually need Implementations forced to stub methods they don’t support One interface per method, everywhere
Dependency inversion Core logic depends on abstractions it owns; details plug in Business rules welded to a database or vendor Every dependency injected through an interface, including the clock and the logger, for no reason

The last column is the clue that matters: every principle has a version of itself that does harm. So the question isn’t which principles are good, but where each one earns its place.

Case 1: swappable email providers #

This is the case where all five principles turn up at once, each with a visible job.

The situation: the blogging platform I run sends sign-in links, confirmations and new-post emails. The platform admin can choose Amazon SES, Postmark, Resend, Mailgun or SMTP, and tests must not send real email.

How SOLID shows up:

  • Dependency inversion: the queue worker depends on a one-method interface, Sender, defined next to the code that uses it, not on any provider’s SDK.
  • Interface segregation: Sender has exactly one method, Send(ctx, email). Nothing needs more.
  • Open/closed: adding a provider means adding an implementation and a settings entry; the queue, retries and templates don’t change.
  • Liskov: every implementation must report failure through the error, so the retry logic treats them all the same. A provider that swallowed errors would break that promise.

This is where SOLID earns its keep: there are seven implementations (five providers plus a recorder for tests and a log sender for development). It’s satisfying to see how small the seam is: one method, and seven very different things fit behind it.

Flowchart: Queue worker, Sender interface: Send(ctx, email), Amazon SES, Postmark, Resend, Mailgun, SMTP, Recorder (tests), Log sender (development)Flowchart: Queue worker, Sender interface: Send(ctx, email), Amazon SES, Postmark, Resend, Mailgun, SMTP, Recorder (tests), Log sender (development)
Diagram source
flowchart LR
  W["Queue worker"] --> I["Sender interface: Send(ctx, email)"]
  I --> SES["Amazon SES"]
  I --> PM["Postmark"]
  I --> RS["Resend"]
  I --> MG["Mailgun"]
  I --> SM["SMTP"]
  I --> RC["Recorder (tests)"]
  I --> LG["Log sender (development)"]

Case 2: a payment integration #

The situation: you take payments through one provider today. Finance mentions that a second one might be needed for another country. The temptation is to build for every provider at once.

What I’d do:

  • Do keep the payment provider behind a narrow interface of your own (CreatePayment, Refund, ParseWebhook), in your terms, not the provider’s. That’s dependency inversion (the hexagonal architecture post builds a whole structure on it), and it also makes testing easy.
  • Don’t chase the false lead of a generic multi-provider framework yet. Write the second implementation when the second provider is real; you’ll learn which differences matter (webhook semantics, idempotency, partial refunds) only then.
  • Watch Liskov here: providers differ in subtle ways (one confirms synchronously, another only by webhook). If callers start checking which provider they have, the abstraction is wrong; fix the interface rather than adding if provider == .... That if is the fingerprint of a broken promise.

Case 3: a small script or internal tool #

The situation: a 200-line tool that reads a CSV, calls an API and writes a report.

What I’d do: ignore most of SOLID. Write functions in a single file. If it grows, split by responsibility (reading, calling, reporting). Interfaces would only add indirection. Here, the over-engineered version is the real culprit.

Single responsibility, properly understood #

This is the principle I think is most often misread, and the real version is far more interesting. The common misreading is that it’s about size. It isn’t. “One reason to change” is about people and causes:

  • The SQL for posts changes when the schema changes.
  • The HTML for posts changes when the design changes.
  • The rule for who may publish changes when the business decides.

If one file mixes all three, a designer’s tweak can break a permission check. The blogging platform separates them into store (SQL), templates (HTML) and handlers (rules and flow). It doesn’t split further than that, because nothing else changes independently. That’s the elegant part: the code’s seams follow the seams in the organisation.

A quick checklist for reviews #

  • Does this module change for more than one kind of reason? Split by reason.
  • Does core logic import a vendor SDK, an HTTP framework or the database driver directly? Put a small interface of your own in between, if the core is worth protecting.
  • Does any caller check which implementation it has? The abstraction leaks.
  • Does this interface have only one implementation and no tests that use a fake? It may not need to exist.

Remember this

  • SOLID is a set of questions for boundaries, not rules for every class.
  • Split by reason to change, and own small interfaces your core depends on.
  • Add the extension point when the second case is real.

Case closed: what I’d do by default #

  1. Separate by reason to change: data access, presentation and rules.
  2. Own the interfaces your core depends on, and keep them small.
  3. Add extension points when the second case is real, not when it’s imaginable.
  4. Treat implementation checks in callers as a design bug.
  5. Keep scripts and small tools simple; SOLID is for code that lives and grows.

Read that way, SOLID isn’t a rulebook so much as five good questions, handed down by people who cared about code that’s pleasant to change. Asking them at the right moments is one of the small joys of the craft.

Like (sign in first) 0 likes 💬 0

Written by

Vishal Kumar

Associate Director at CapGrid, running product and engineering in a CPTO capacity. 10+ years building distributed, multi-tenant SaaS and AI platforms. AWS Certified Solutions Architect - Professional. Based in Gurugram.

Comments

No comments yet.

Sign in to comment. We'll email you a link; no password needed.