Skip to content

Instantly share code, notes, and snippets.

@trikitrok
Last active November 13, 2023 10:23
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/fe05836a31eb6dbf04c19da9b94b4a3a to your computer and use it in GitHub Desktop.
Save trikitrok/fe05836a31eb6dbf04c19da9b94b4a3a 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/
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