CouplersHigh

Feature Envy: What It Costs and How to Fix It

A method that uses data and methods from another class more than from its own class.

Model cost, team of 8$6K-$24K/yr
Severity
4/5
CategoryCouplers
Detection4 tools

What It Is

Feature Envy occurs when a method in Class A spends most of its time working with data from Class B. The method reaches into Class B, extracts values, performs calculations, and possibly puts results back. The method 'envies' Class B's features and should probably live in Class B instead. Feature Envy is one of the most common coupling smells and is a strong indicator that responsibilities are misallocated between classes.

Threshold: When a method accesses 3+ fields or methods of another class, and fewer than 2 of its own, it has Feature Envy. The 'principle of proximity' applies: logic should live near the data it operates on.

Why It Costs Money

1

Changes to Class B's structure break Class A. When Feature Envy exists, Class A depends on the internal structure of Class B. Any change to B's fields or methods requires updating A, even though A should not care about B's internals.

2

Logic duplication follows. When multiple classes envy the same features of Class B, the same logic appears in multiple places. Each envious method implements its own version of the calculation, leading to inconsistency.

3

Testing becomes coupled. To test the envious method in Class A, you must set up Class B with specific state. This creates brittle tests that break when Class B changes, even though the test is nominally for Class A.

Specific Cost Mechanisms

  • ●Structural coupling: each change to Class B potentially breaks envious methods in other classes
  • ●Logic scattering: the same calculation in multiple envious methods creates inconsistency bugs
  • ●Test brittleness: tests for envious methods break when the envied class changes

Estimated Annual Cost

Cost of one instance a year by team size, from our model at $180K fully-loaded cost per engineer. Low and high use the bottom and top of the High inputs; mid is halfway. See full methodology.

Team SizeLowMidHigh
3 devs$3K$7K$11K
5 devs$4K$10K$16K
8 devs$6K$15K$24K
10 devs$7K$19K$30K
20 devs$14K$35K$57K

These are model outputs, not measurements. Every input is on the cost model page, and the same model produces the figures on the 22 smells page. Put in your own team and cost in the smell profile calculator.

How to Detect It

Specific rules and thresholds for automated detection. See full tool comparison.

SonarQube
squid:S1200

High class coupling indicates potential Feature Envy

CodeClimate
feature-envy

Directly detects methods that access foreign data more than local data

PMD
LawOfDemeter

Method chain length indicates reaching into other objects

IntelliJ IDEA
Feature envy inspection

Detects methods with more foreign references than local

Refactoring Patterns

Proven techniques to eliminate this smell. See all refactoring patterns.

Move Method

The method clearly belongs in the class it envies

Effort (our estimate): 1-3 hours
Impact: Eliminates the coupling entirely

Extract Method then Move

Only part of the method envies another class

Effort (our estimate): 2-4 hours
Impact: Separates the envious logic and relocates it

Introduce Delegate

Moving the method would create a circular dependency

Effort (our estimate): 2-4 hours
Impact: Maintains separation while reducing direct access to foreign data

Related Smells

Updated November 2026