Command Palette

Search for a command to run...

All posts
6 min read

SOLID Is About Production, Not Purity

Stop memorizing the letters. Each SOLID principle is the scar of a production incident. Learn the incidents.

The syllabus says: 'Do not memorize SOLID definitions; ask what production problem each principle prevents.' Here is that translation — each letter attached to the incident that made it famous.

S — the 900-line controller

Single Responsibility exists because 'God classes' — one class that parses requests, does business logic, writes to the DB and sends emails — become files nobody dares touch. Every change touches the one file, every author waits for the last author. Production problem: change is slow and terrifying. Fix: one class, one reason to change.

O — the switch that grew forever

Open/Closed answers the 'seventh payment type' problem. Without it, adding a payment method means editing the switch in PaymentProcessor and re-testing the entire payment path. With a strategy map, it means one new class and one registration line. Production problem: regression risk grows with every new feature instead of staying constant.

L — the square that broke the world

Liskov Substitution is the Square-extends-Rectangle story: if setting a rectangle's width changes its height (because the subclass enforces squareness), every caller that 'just treats it as a rectangle' misbehaves. Production problem: subclasses that quietly break base-class invariants — the worst bugs to find because nothing tells you to suspect the subclass.

I — the fat interface

Interface Segregation appears when a 12-method interface forces every implementer to write five throw UnsupportedOperationException() stubs. Production problem: misleading contracts and fake implementations that explode at runtime. Fix: split into role interfaces.

D — the test that needed a real database

Dependency Inversion is what makes your unit tests green without Spring. Depend on the port (interface), inject the adapter (fake for tests). Production problem: without it, 'test the service' means 'boot a Postgres'. With it, the test is three lines.

The interview answer

When an interviewer asks about SOLID, answer with the incident: 'OCP matters here because a sixth spot type costs one strategy class, not a revision of the core flow.' That's the difference between someone who read a blog and someone who shipped.

lldsolidjava