Inappropriate Intimacy: What It Costs and How to Fix It
Two classes that depend too heavily on each other's internal details, creating a tangled, inseparable pair.
What It Is
Inappropriate Intimacy occurs when two classes know too much about each other's internal implementation. They access each other's private or protected members, depend on each other's internal data structures, and cannot be understood, tested, or deployed independently. The coupling is bidirectional: Class A depends on B's internals and B depends on A's internals, creating a tightly bound pair that effectively functions as a single, oversized class split across two files.
Why It Costs Money
Neither class can be changed independently. Any modification to one class's internals requires checking and potentially updating the other class. This doubles the effort for every change and makes code review more complex because reviewers must understand both classes simultaneously.
Testing in isolation is impossible. You cannot test Class A without setting up Class B in a specific internal state, and vice versa. This creates fragile test suites where a change in one class breaks tests for both.
Reuse is blocked. Neither class can be extracted for use in another context because it drags its partner along. The pair becomes an inseparable unit that must be maintained as a whole.
Specific Cost Mechanisms
- ●Coupled changes: every modification requires understanding and updating two classes, doubling effort
- ●Test fragility: changes to either class break tests for both classes
- ●Reuse prevention: the coupled pair cannot be extracted or reused independently
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 | $3,500 | $8,400 | $16,800 |
| 5 devs | $5,800 | $14,000 | $28,000 |
| 10 devs | $8,750 | $21,000 | $28,000 |
| 20 devs | $11,600 | $28,000 | $28,000 |
How to Detect It
Specific rules and thresholds for automated detection. See full tool comparison.
High bidirectional class coupling
Classes that reference each other heavily
Counts the number of unique types referenced by a class
Bidirectional imports between modules indicate intimacy
Refactoring Patterns
Proven techniques to eliminate this smell. See all refactoring patterns.
Move Method/Field
One class has methods that primarily use the other class's data
Extract Class
The shared behaviour between both classes forms a coherent concept
Hide Delegate
One class exposes its internal collaborator to the other