CouplersHigh

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.

Annual Cost$3.5k - $28k
Severity
4/5
CategoryCouplers
Detection4 tools

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.

Threshold: When two classes import each other (circular dependency) or when one class accesses 5+ members of another, inappropriate intimacy is present. The strongest indicator is that you cannot explain one class without referencing the other.

Why It Costs Money

1

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.

2

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.

3

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 SizeSmall (<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.

SonarQube
squid:S1200

High bidirectional class coupling

CodeClimate
complex-logic / method-count

Classes that reference each other heavily

PMD
CouplingBetweenObjects

Counts the number of unique types referenced by a class

Dependency analysis
Circular dependency detection

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

Effort: 2-6 hours
Impact: Reduces coupling by consolidating related logic

Extract Class

The shared behaviour between both classes forms a coherent concept

Effort: 4-8 hours
Impact: Creates a third class that owns the shared concern

Hide Delegate

One class exposes its internal collaborator to the other

Effort: 1-3 hours
Impact: Introduces a clean interface between the coupled classes

Related Smells