Leaking Abstraction
Implementation details bubbling up through an abstraction.
“All non-trivial abstractions, to some degree, are leaky.” – Joel Spolsky
Signs of Use (Symptoms)
- Users of an abstraction must know about its internals to use it correctly.
- Exceptions or errors from lower layers propagate up unchanged.
Why it is bad (Consequences)
- Abstraction fails: The whole point of abstractions is to hide complexity.
- Coupling: Clients become coupled to the implementation.
Why it happens (Root Cause)
Abstractions are hard. Edge cases expose the underlying reality.
Refactoring Solution
- Strengthen the abstraction: Handle edge cases within it.
- Wrap exceptions: Translate low-level errors to domain errors.
Code example
Typescript
Bad
Good