fixing Feature Envy by backtracking

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?

Advertisements

One thought on “fixing Feature Envy by backtracking

  1. I’ve not really thought about this before, but basically I keep a Utils class around whose aim is to be empty. It very rarely has state, so usually only contains statics. So, unconsciously, I decompose whatever is heading in that direction.

    I don’t agonise over methods not having an obvious home; sooner or later they find one. Removing the duplication takes priority.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s