refactoring : feature envy
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user