Skip to content

Latest commit

 

History

History
63 lines (49 loc) · 2.06 KB

File metadata and controls

63 lines (49 loc) · 2.06 KB
Root.Smell.ClassSmell.FeatureEnvy Parent Index
Sibling aspects ClassLength DataClump

FeatureEnvy

This aspect detects occurrences of feature envy in your codebase.

Feature envy describes classes that excessively use methods of other classes.

Subaspects

This aspect does not have any sub aspects.

Example

public class Phone {
    private final String unformattedNumber;
    public Phone(String unformattedNumber) {
        this.unformattedNumber = unformattedNumber;
    }
    public String getAreaCode() {
        return unformattedNumber.substring(0,3);
    }
    public String getPrefix() {
        return unformattedNumber.substring(3,6);
    }
    public String getNumber() {
        return unformattedNumber.substring(6,10);
    }
}
public class Customerprivate Phone mobilePhone;
    public String getMobilePhoneNumber() {
        return "(" +
            mobilePhone.getAreaCode() + ") " +
            mobilePhone.getPrefix() + "-" +
            mobilePhone.getNumber();
    }
}

Importance

This smell may occur after fields are moved to a data class; which makes the code less readable, and difficult to debug.

How to fix this

Move the operations on data to the newly defined class(given that the fields of one class were moved to this class) as well.