Feature Envy¶
Flag a method whose cross-class field and method accesses to another class outnumber accesses to its own, signalling that the behavior lives at the wrong address and should be relocated to the class whose data it operates on.
Core Idea¶
Feature envy is the object-oriented code smell in which a method is more interested in another class's data than its own: its body is dominated by accesses to the other class's fields and methods, and its coupling to that class exceeds coupling to its own. The method is in the wrong place. Named by Fowler, it marks responsibility misplacement — not a runtime error but a maintenance tax, since every change to the data owner's interior propagates into the envious method.
Scope of Application¶
Lives wherever object-oriented responsibility is allocated across classes and a method can end up at the wrong address.
- Anemic domain models — logic pooled in service classes reaching into passive data classes.
- God controllers in MVC — a controller method reaching deep into model state.
- Manager-class accretion — an
OrderManagercomputing whatOrdershould own. - Utility-class drift — helpers picking at a domain object's internals rather than delegating.
- Cross-service reads — one service making many small reads against another's state.
Clarity¶
The name converts a reviewer's vague unease into a locally detectable diagnosis with a bound remedy: this method envies class B, so move it to B. It makes legible that correctness and responsibility placement are different axes — the method can produce right output while living at the wrong address, so the problem registers as a maintenance tax, not a bug. It gives coupling a direction and a locality the bare notion lacks.
Manages Complexity¶
Judging responsibility placement across a codebase is a whole-graph problem; feature envy collapses it to a local one, readable from a single method's body via one countable scalar — cross-class fan-out versus in-class fan-out. Recognition and remedy arrive together (the smell binds to Move Method), and a static analyzer can surface candidates mechanically. The correctness-versus-placement split lets the reviewer read the cost off the fan-out alone.
Abstract Reasoning¶
The smell licenses a recognize-locate-relocate chain: a diagnostic counting move (cross-class fan-out signals misplacement), a boundary-drawing move separating correctness from responsibility placement and the smell from god class and shotgun surgery siblings, a predictive move recasting the cost as a future stream of forced edits, and an interventionist move (Move Method closes the change-propagation path).
Knowledge Transfer¶
Within software design the smell transfers as mechanism — its four-part signature, countable diagnostic, and Move Method remedy carry across anemic models, god controllers, and even microservice boundaries, with Tell-Don't-Ask and the Law of Demeter travelling along. Beyond software the portable structure is the parent cohesion — behavior should live with the data it operates on — of which feature envy is one named OO violation. The Move-Method/fan-out apparatus stays home; invoking "feature envy" for org design is analogy in naming.
Relationships to Other Abstractions¶
Current abstraction Feature Envy Domain-specific
Parents (2) — more general patterns this builds on
-
Feature Envy is a kind of Code Smell Domain-specific
Feature Envy is the code-smell species whose cross-class access pattern provides defeasible evidence that a method's responsibility resides on the wrong class.
-
Feature Envy is part of Coupling Prime
Outbound dependence on another class's state and behavior is the measurable coupling constituent from which feature envy is diagnosed.
Hierarchy paths (5) — routes to 5 parentless roots
- Feature Envy → Code Smell → Evidence → Provenance → Traceability → Observability
- Feature Envy → Coupling
- Feature Envy → Code Smell → Evidence → Provenance → Attestation → Authentication
- Feature Envy → Code Smell → Evidence → Provenance → Traceability → Transformation → Function (Mapping)
- Feature Envy → Code Smell → Evidence → Provenance → Custody Transfer → State and State Transition → Phase Space
Neighborhood in Abstraction Space¶
Feature Envy sits in a sparse region of the domain-specific corpus (97th percentile for distinctiveness): few abstractions share its structure, so a faithful description tends to retrieve it precisely.
Family — Adversarial Exploits & Structural Boundaries (12 abstractions)
Nearest neighbors
- Data Class — 0.82
- Long Parameter List — 0.80
- Memory Management — 0.80
- Insecure Deserialization — 0.80
- Universal property — 0.79
Computed from structural-signature embeddings · 2026-07-12