Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
Root.Smell.ClassSmell.FeatureEnvy Parent Index
Sibling aspects ClassSize DataClump

FeatureEnvy

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.