Last active
November 13, 2023 10:23
-
-
Save trikitrok/fe05836a31eb6dbf04c19da9b94b4a3a 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/ | |
class CheckoutHandlder { | |
// ... | |
convertToCurrency(price, currencyTo) { | |
if (currencyTo === "EUR") { | |
return price * 0.9; | |
} else if (currencyTo === "CAD") { | |
return price * 1.35; | |
} else { | |
throw new Error("Unrecognized currency: " + currencyTo); | |
} | |
} | |
} | |
class SimpleCurrencyConverter { | |
public construct(currencyTo) { | |
this.currencyTo = currencyTo; | |
} | |
convert(price) { | |
if (this.currencyTo === "EUR") { | |
return price * 0.9; | |
} else if (this.currencyTo === "CAD") { | |
return price * 1.35; | |
} else { | |
throw new Error("Unrecognized currency: " + this.currencyTo); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment