LESSON 10.2
Pattern overuse
Avoid 'design pattern mania' and premature abstraction: applying complex GoF patterns to simple problems where a direct function or class is far superior.
6 min read
After reading about design patterns for the first time, many engineers suffer from Pattern Mania: the compulsive urge to shoehorn every pattern into every class. A simple requirement like "multiply price by quantity" suddenly turns into an AbstractPriceCalculatorFactoryProviderVisitor.
Patterns are solutions to specific, recurring design problems. When applied in the absence of the underlying problem, they introduce Accidental Complexity that slows teams down.
The problem
// Pattern Overuse Nightmare:
// Problem: Add two numbers and print result.
class AbstractCalculationStrategyFactory {
createStrategy() {
return new ConcreteAdditionStrategy();
}
}
class ConcreteAdditionStrategy {
execute(a, b) { return a + b; }
}
// Why not just: const add = (a, b) => a + b; ?When simple is better: KISS & YAGNI
- KISS (Keep It Simple, Stupid): Start with the most straightforward implementation that works.
- YAGNI (You Aren't Gonna Need It): Do not write code for future requirements that may never arrive.
- The Rule of Three: Refactor toward a pattern when you see the third repetition of a variation, not on the first.
In code
Signs you are over-engineering
- 1-method interfaces with only 1 implementation: If an interface only has
FooServiceImpl, delete the interface unless a second implementation or mock genuinely exists. - Layers of pure passthrough delegation: If
Controller -> Service -> Manager -> Helper -> DAOeach do nothing but pass the arguments unchanged to the next layer. - Premature extensibility: Adding plugin hooks and reflection dynamic loading for a feature that only 1 internal team will ever use.
Related patterns
- Pattern Overuse vs Refactoring: Patterns should emerge organically through refactoring, not be pre-imposed upon blank files.
- YAGNI vs Open/Closed: Open/Closed means writing code that can be extended easily; it does NOT mean writing every theoretical extension upfront.
Try it
Shopping Cart Domain LLD
Compare an over-engineered cart hierarchy against a clean, functional calculation pipeline.