intermediate 2 min answer

Which SOLID principle produces the most practical benefit in a large codebase, and which is most often misapplied?

soliddependency-inversionabstractionover-engineeringjetbrainsconceptual
Show the full answer Hide the answer

The most practically valuable

Dependency inversion. Depending on abstractions rather than concretions is what makes a large codebase testable, makes components replaceable, and prevents a low-level detail — a database driver, a file format, a vendor client — from propagating through the whole system.

It is also the principle that enables the others: single responsibility is easier to maintain when dependencies are injected, and open-closed extension usually depends on an abstraction to extend against.

The practical form is unglamorous: business logic does not import infrastructure. That single rule, enforced by a static check on dependency direction, delivers most of the benefit.

The most often misapplied

Open-closed, interpreted as "make everything extensible in advance".

This produces speculative abstraction: interfaces with one implementation, configuration for variation that never occurs, plugin points nobody uses. Each is a guess about the future that adds indirection now and is usually wrong about what varies.

The disciplined form is to make something extensible when the second case arrives, not when it is imagined. Two implementations tell you where the seam belongs; one implementation and an imagination do not.

The one that is most commonly violated without noticing

Interface segregation. A large interface implemented by several classes, most of which implement half of it and throw on the rest. The symptom is unimplemented methods, and the cost is that every consumer depends on methods it does not use — so a change for one consumer affects all of them.

The framing that keeps these useful

These are heuristics that describe what well-factored code tends to look like, not rules to apply mechanically. Applied dogmatically they produce codebases with more indirection than logic, where following a single request means opening nine files.

The test for any application of them is the same: does this reduce the cost of a change we can reasonably expect? If the change is hypothetical, the abstraction is speculative and its cost is certain.