Code quality and technical debt

Feature envy

Also known as Feature envy, Feature envy in software engineering

By WeavePublished 1 min read

Definition

A code smell in which one method appears more interested in another object’s data than in its own context.

What it means

Feature envy describes a method that repeatedly reads another object’s fields or calls its methods to perform behavior that may belong with that object. The smell can indicate misplaced responsibility, but it can also occur in reporting, transformation, or orchestration code where external data is the purpose.

Example

A shipping quote method in an order service reads many carrier details and reproduces carrier-specific rules. Moving the relevant behavior behind a carrier policy interface reduces duplicated knowledge.

Limitations

Moving the method automatically may create a dependency cycle or mix domain and integration concerns. Measure the change in coupling and test clarity, and keep orchestration explicit when it is the actual responsibility.

How to use the signal

Check whether the method is truly violating responsibility or is intentionally transforming data at an integration or reporting boundary.

Weave can help compare feature-envy refactors with review feedback and later fixes. Static-analysis findings identify candidates, while Weave supplies the delivery context.

How this relates to Weave

Weave can help compare feature-envy refactors with review feedback and later fixes. Static-analysis findings identify candidates, while Weave supplies the delivery context.

Explore Engineering intelligence

Sources and further reading

  1. SonarSource code metrics and analysis documentation