Feature Envy occurs when a method is more interested in the features (methods and fields) of other classes than its own. The solution if it exists at all, is straightforward; move the method to the class that it is most envious of, passing any parameters the new method requires. If only part of the method demonstrates this envy, extract that part and then move the new method into the envied class. Sometimes this is not possible, since the envied class may be available only in a non-modifiable form.
Although conceptually straightforward, there are intricacies. For example:
The approach we have taken is straightforward. Let:
m be the method for which we want to calculate Feature Envy Fc be the set of features used by m that belong to type c cm be the class in which m is defined
Then:
Feature Envy = maxc ≠ cm(|Fc|) - |Fcm|
Note: I have only included features for types derived by Eclipse from source, rather than in binary form. This is to prevent unhelpful reports of high values of Feature Envy which cannot be eliminated because the envied type is an external library.