Root.Smell.ClassSmell.FeatureEnvy |
Parent | Index |
Sibling aspects | ClassLength | DataClump |
This aspect detects occurrences of feature envy in your codebase.
Feature envy describes classes that excessively use methods of other classes.
This aspect does not have any sub aspects.
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 Customer…
private Phone mobilePhone;
public String getMobilePhoneNumber() {
return "(" +
mobilePhone.getAreaCode() + ") " +
mobilePhone.getPrefix() + "-" +
mobilePhone.getNumber();
}
}
This smell may occur after fields are moved to a data class; which makes the code less readable, and difficult to debug.
Move the operations on data to the newly defined class(given that the fields of one class were moved to this class) as well.