refactoring : feature envy

This commit is contained in:
haerong22
2022-03-21 15:31:39 +09:00
parent 6a0d19bc72
commit a01616f3a3
6 changed files with 120 additions and 0 deletions

View File

@@ -0,0 +1,13 @@
package com.example.refactoring._09_feature_envy;
public class Bill {
private ElectricityUsage electricityUsage;
private GasUsage gasUsage;
public double calculateBill() {
return electricityUsage.getElectricityBill() + gasUsage.getGasBill();
}
}

View File

@@ -0,0 +1,25 @@
package com.example.refactoring._09_feature_envy;
public class ElectricityUsage {
private double amount;
private double pricePerUnit;
public ElectricityUsage(double amount, double pricePerUnit) {
this.amount = amount;
this.pricePerUnit = pricePerUnit;
}
public double getAmount() {
return amount;
}
public double getPricePerUnit() {
return pricePerUnit;
}
public double getElectricityBill() {
return this.getAmount() * this.getPricePerUnit();
}
}

View File

@@ -0,0 +1,25 @@
package com.example.refactoring._09_feature_envy;
public class GasUsage {
private double amount;
private double pricePerUnit;
public GasUsage(double amount, double pricePerUnit) {
this.amount = amount;
this.pricePerUnit = pricePerUnit;
}
public double getAmount() {
return amount;
}
public double getPricePerUnit() {
return pricePerUnit;
}
public double getGasBill() {
return this.getAmount() * this.getPricePerUnit();
}
}

View File

@@ -0,0 +1,15 @@
package com.example.refactoring._09_feature_envy._before;
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;
}
}

View File

@@ -0,0 +1,21 @@
package com.example.refactoring._09_feature_envy._before;
public class ElectricityUsage {
private double amount;
private double pricePerUnit;
public ElectricityUsage(double amount, double pricePerUnit) {
this.amount = amount;
this.pricePerUnit = pricePerUnit;
}
public double getAmount() {
return amount;
}
public double getPricePerUnit() {
return pricePerUnit;
}
}

View File

@@ -0,0 +1,21 @@
package com.example.refactoring._09_feature_envy._before;
public class GasUsage {
private double amount;
private double pricePerUnit;
public GasUsage(double amount, double pricePerUnit) {
this.amount = amount;
this.pricePerUnit = pricePerUnit;
}
public double getAmount() {
return amount;
}
public double getPricePerUnit() {
return pricePerUnit;
}
}