Feature Envy
ELI5 — The Vibe Check
Feature envy is when a function spends more time poking around in another class's data than its own. It's like a neighbor who's always borrowing your tools — at some point, the function should just move to where the data lives. If your method calls other.getX(), other.getY(), other.getZ() more than it uses its own stuff, it's jealous of the wrong class.
Real Talk
Feature envy is a code smell where a method accesses data from another object more than its own. Identified by Martin Fowler, it suggests the method belongs in the other class. The refactoring solution is typically Move Method — relocating the method to the class whose data it primarily uses, improving cohesion and reducing coupling.
When You'll Hear This
"This method has serious feature envy — it calls the User object 15 times." / "Move the method to where the data lives and kill the feature envy."
Related Terms
Code Smell
Code Smell is when code isn't technically broken but something feels off — like a 500-line function, a class named 'Manager' that does everything, or a com...
Cohesion
Cohesion is how well the things inside a module belong together. High cohesion means all the stuff in a class is related — like a toolbox full of tools.
Coupling
Coupling is how much two pieces of code depend on each other. Tight coupling means changing one breaks the other — like Siamese twins.
Refactor
Refactoring is cleaning and reorganizing your code without changing what it does — like tidying your room without throwing anything away.
Shotgun Surgery
Shotgun surgery is when one small change requires you to modify dozens of files across the codebase — like firing a shotgun and hitting everything.