Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save sezemiadmin/09387c504f095dc1a695d1a445d8d92b to your computer and use it in GitHub Desktop.
Save sezemiadmin/09387c504f095dc1a695d1a445d8d92b to your computer and use it in GitHub Desktop.
"リファクタリングのポイント" のサンプルコード (Replace Temp with Query)
package composing_methods.replace_temp_with_query.after;
public class Example {
private int quantity;
private int itemPrice;
public double getPrice() {
return basePrice() * discountFactor();
}
private double discountFactor() {
if(basePrice() > 1000) {
return = 0.95;
} else {
return = 0.98;
}
}
private int basePrice() {
return quantity * itemPrice;
}
}
package composing_methods.replace_temp_with_query.after;
public class Example {
private int quantity;
private int itemPrice;
public double getPrice() {
int basePrice = quantity * itemPrice;
double discountFactor;
if(basePrice > 1000) {
discountFactor = 0.95;
} else {
discountFactor = 0.98;
}
return basePrice * discountFactor;
}
}
package composing_methods.replace_temp_with_query.after;
public class Example {
private int quantity;
private int itemPrice;
public double getPrice() {
return basePrice() * discountFactor();
}
private double discountFactor() {
if(basePrice() > 1000) {
return = 0.95;
} else {
return = 0.98;
}
}
private int basePrice() {
return quantity * itemPrice;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment