Topic 03

SOLID: Designing for Change

Concept

SOLID is a famous set of five design principles for writing object-oriented code that stays flexible and easy to extend. You don't need to master them as a beginner — you need to recognize the names when they come up and grasp the single idea they all serve: build code that's open to change without rewrites.

The name is an acronym, one letter per principle. We'll take them in pairs and then name the thread that ties them together. Don't worry about applying them yet; aim to recognize them.

A picture for the whole set: Lego bricks with standard studs. Because every brick connects the same agreed way, you can add and swap pieces freely, without re-gluing the whole model. SOLID code is built to be extended like that.

LetterPrincipleIn plain English
SSingle ResponsibilityEach part should do just one job
OOpen/ClosedExtend behavior without modifying existing code
LLiskov SubstitutionA subtype should work wherever its base type does
IInterface SegregationSmall, focused interfaces over big general ones
DDependency InversionDepend on abstractions, not concrete details

S and O: One Job, Open to Extension

Single Responsibility says each part should have one reason to change — one job. A class that handles both saving data and formatting screens has two jobs and will be pulled in two directions. Open/Closed says code should be open to extension but closed to modification: you should be able to add new behavior by adding new code, not by rewriting (and risking breaking) what already works.

L and I: Substitutable and Focused

Liskov Substitution says if something claims to be a kind of X, it must behave like an X everywhere an X is expected — no nasty surprises when you swap it in. Interface Segregation says prefer small, focused interfaces (sets of capabilities) over one giant interface that forces parts to depend on methods they don't use. Both keep parts honest and loosely connected.

D: Depend on Abstractions

Dependency Inversion is the one you'll hear most. It says code should depend on abstractions — general ideas — rather than concrete details. Instead of the order code depending directly on "email", it depends on a general "notifier" idea, and email is just one thing that fills that role. Swap in a different notifier later and the order code never changes. This is the loose-coupling principle from Chapter 5, made into a coding rule.

The Common Thread

All five serve one goal: reduce the blast radius of change. Each principle, in its own way, keeps a change from rippling out and breaking distant code. That's why SOLID is really an elaboration of coupling and cohesion: focused parts, loose connections, and clear contracts, so the system bends instead of breaking. You don't have to apply all five perfectly — the habits behind them help any codebase.

Cadence shows the D in action. Its notification code depends on a generic "Notifier" idea, not on email specifically. So when the team adds push notifications, they add a new brick that fills the Notifier role — the habit and reminder code that use a notifier never change. A new capability slots in like a Lego piece, exactly as SOLID intends.

Common Confusions
  • "SOLID is only for huge enterprise systems." The habits behind it — one job per part, depend on abstractions — help any codebase, large or small. They're good design, not enterprise ceremony.
  • "You must apply all five principles everywhere, perfectly." They're guidance, not a checklist to force. Use them where they help; rigidly applying all five can itself over-complicate simple code.
  • "SOLID means more abstraction is always better." Over-abstraction is its own smell. The goal is the right amount that contains change, not layers of indirection added for their own sake.
Why It Matters
  • SOLID is the most-cited design vocabulary in interviews and code reviews — recognizing the names lets you follow and join those conversations.
  • It operationalizes the coupling-and-cohesion ideas from Chapter 5 into concrete coding habits you can actually apply.
  • The shared goal — shrinking the blast radius of change — is the heart of writing software that survives years of evolution.

Knowledge Check

What does the "S" (Single Responsibility) principle say?

  • Each part should have just one job, and one reason to change
  • Each part should depend only on abstractions, never on details
  • The whole program should be written as one single large class
  • Each part should contain only one single line of code

What is the single goal that all five SOLID principles serve?

  • Reducing the blast radius of change so edits don't ripple outward
  • Making the finished program run as fast as it possibly can
  • Writing the program in the fewest possible lines of code
  • Adding as many separate layers of abstraction as you possibly can everywhere

What does Dependency Inversion (the "D") recommend?

  • Depend on general abstractions rather than on concrete details
  • Make sure each part of the code has only one single job
  • Run all of the program's code in the reverse order it was written
  • Never use any outside libraries or dependencies in the project

Why is "you must apply all five SOLID principles perfectly everywhere" a confusion?

  • They're guidance, and forcing all five can over-complicate simple code
  • Because the five principles only apply to web applications
  • Because the five principles directly contradict one another
  • Because the SOLID principles are very old and are no longer used by anyone at all

How does SOLID relate to coupling and cohesion from the design chapter?

  • It turns low coupling and high cohesion into concrete coding habits
  • It directly contradicts coupling and cohesion and replaces them both entirely
  • It measures how quickly the software runs, unlike coupling
  • It describes how many developers a project should have

You got correct