fixing Feature Envy by backtracking

Posted on January 15, 2010

1


After a conversation this week with Hugh Sasse about Feature Envy and Utility Functions, I realised I’ve evolved my approach to dealing with them:

When Reek tells me about one of these smells, my first step is to inline the smelly method back into all of its callers. Then I look for ways to fix the resulting duplication without extracting the same method again. Sometimes the re-formed methods break apart in new ways (compared to when they were first written), other times I see opportunities to peel off new classes. (One thing I never do these days is to introduce inheritance relationships in order to remove duplication; I look hard for ways to solve it through delegation, often to a new class, or I leave the duplication in place for the time being.)

This approach seems to be working well for me at this early stage. Have you tried this or something similar? How did it turn out?

Tagged:
Posted in: refactoring