tonykang22 / study

0 stars 0 forks source link

[Refactoring] 냄새 9. 기능 편애 #23

Open tonykang22 opened 2 years ago

tonykang22 commented 2 years ago

냄새 9. 기능 편애 (Feature Envy)


예시

public class Bill {

    private ElectricityUsage electricityUsage;

    private GasUsage gasUsage;

    public double calculateBill() {
        var electicityBill = electricityUsage.getAmount() * electricityUsage.getPricePerUnit();
        var gasBill = gasUsage.getAmount() * gasUsage.getPricePerUnit();
        return electicityBill + gasBill;
    }

}


각각 클래스에서 계산을 하도록 분리하고 난 코드이다.

public class Bill {

    private ElectricityUsage electricityUsage;

    private GasUsage gasUsage;

    public double calculateBill() {
        return electricityUsage.getElecticityBill() + gasUsage.getGasBill();
    }

}