Last active
May 3, 2023 12:26
-
-
Save trikitrok/eccd76bb9b40906e61833c058b57ef54 to your computer and use it in GitHub Desktop.
This file contains 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
// From Fixing Object oriented abusers, Manh Phan https://ducmanhphan.github.io/2020-01-24-Fixing-object-oriented-abusers/ | |
public class CheckoutHandlder { | |
// ... | |
public double convertToCurrency(double price, String currencyTo) { | |
if (currencyTo.equalsIgnoreCase("EUR")) { | |
return price * 0.9; | |
} else if (currencyTo.equalsIgnoreCase("CAD")) { | |
return price * 1.35; | |
} else { | |
throw new IllegalArgumentException("Unrecognized currency: " + currencyTo); | |
} | |
} | |
} | |
public class SimpleCurrencyConverter { | |
private String currencyTo; | |
public SimpleCurrencyConverter(String currencyTo) { | |
this.currencyTo = currencyTo; | |
} | |
public double convert(double price) { | |
if (currencyTo.equalsIgnoreCase("EUR")) { | |
return price * 0.9; | |
} else if (currencyTo.equalsIgnoreCase("CAD")) { | |
return price * 1.35; | |
} else { | |
throw new IllegalArgumentException("Unrecognized currency: " + currencyTo); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment