Last active
July 10, 2018 01:41
-
-
Save sezemiadmin/09387c504f095dc1a695d1a445d8d92b to your computer and use it in GitHub Desktop.
"リファクタリングのポイント" のサンプルコード (Replace Temp with Query)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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