The Interface That Made Everything Harder
I used to think that putting an interface in front of every class was good design. It made the class diagram look tidy. It also made a codebase impossible to navigate.
An interface earns its place when it marks a meaningful boundary. Payment gateways, external services, persistence, and clocks are obvious candidates. A CustomerNameFormatter that has one implementation and no credible second behavior is not automatically a boundary. Sometimes it is just another file to open.
The cost is not typing. It is indirection. When tracing a defect, each extra abstraction asks the reader to reconstruct a dependency graph before understanding the actual work. That cost compounds when every service delegates to another service whose only job is delegation.
Consider testing. If an object contains ordinary deterministic business logic, instantiate it and assert the result. If it reaches a database or a volatile external dependency, isolate that boundary. A test suite made entirely of mocks can go green while the application fails the first time the components meet.
The rule I settled on is simple: start concrete, introduce an interface at the first real variation or isolation requirement, and keep the public surface small. I would rather refactor one concrete class later than maintain twenty speculative abstractions today.
A useful code review question is not "Where is the interface?" It is "What would become harder if this dependency were concrete?" If nobody can answer, the interface is probably solving a problem we do not have.
Top comments (0)