Skip to content

Instantly share code, notes, and snippets.

@trikitrok
Last active May 3, 2023 12:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save trikitrok/eccd76bb9b40906e61833c058b57ef54 to your computer and use it in GitHub Desktop.
Save trikitrok/eccd76bb9b40906e61833c058b57ef54 to your computer and use it in GitHub Desktop.
// 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