Alternative Classes with Different Interfaces: What It Costs and How to Fix It
Two or more classes that perform similar functions but have incompatible method names and signatures.
What It Is
This smell occurs when two or more classes do essentially the same thing but expose different interfaces. For example, one notification class uses send(message, recipient) while another uses dispatch(payload, target). Callers cannot use them interchangeably, so switching between implementations requires rewriting all call sites. The classes should implement a common interface, but because they were written independently (often by different developers or at different times), they diverged in naming and structure.
Why It Costs Money
Switching implementations requires rewriting call sites. When you decide to replace one email sender with another, every caller must change because the method names and parameter structures differ.
Code that should be generic must be duplicated. You cannot write a single function that works with both classes, so you write adapter code or duplicate logic.
Testing doubles are inconsistent. Mocks for one implementation do not work for the other, doubling test maintenance.
Specific Cost Mechanisms
- ●Implementation switching: rewriting call sites costs 4-12 hours per switch instead of near-zero with a shared interface
- ●Adapter proliferation: wrapper classes that translate between interfaces add complexity and maintenance cost
- ●Duplicate test infrastructure: separate mocks and test setups for functionally identical classes
Estimated Annual Cost
Cost per instance by team size and codebase size. Based on $120,000 average developer salary. See full methodology.
| Team Size | Small (<50k LOC) | Medium (50k-200k) | Large (200k+) |
|---|---|---|---|
| 3 devs | $1,800 | $4,200 | $8,400 |
| 5 devs | $3,000 | $7,000 | $14,000 |
| 10 devs | $4,500 | $10,500 | $14,000 |
| 20 devs | $6,000 | $14,000 | $14,000 |
How to Detect It
Specific rules and thresholds for automated detection. See full tool comparison.
Interface segregation violations (indirect)
Detects structurally similar classes with different names
Flags concrete type references that should use interfaces
Suggests shared interfaces when similar classes are detected
Refactoring Patterns
Proven techniques to eliminate this smell. See all refactoring patterns.
Extract Superclass/Interface
Two classes have overlapping behaviour that should be unified
Rename Method
Classes do the same thing but use different names
Move Method
Behaviour in one class belongs in the other