How to Unabstract an Abstraction
Abstractions in code are easy to add and challenging to remove. Sometimes we feel stuck with them. But the good news is, you can back out of almost any abstraction with the right mindset. Let’s look at an example. A Breaking Abstraction Imagine a currency formatter. function formatPrice(amount) { return `$${amount.toFixed(2)}` } formatPrice(10) // "$10.00" Soon our company decides to launch in Europe. Let’s add that conditional. function formatPrice(amount, currency) { if (currency === "EUR") return `€${amount.toFixed(2)}` return `$${amount.toFixed(2)}` } formatPrice(10) // "$10.00" formatPrice(10, "EUR") // "€10.00" 😊 Hang on; the Czech Republic puts the currency symbol after the monetary amount. I guess we have to add a conditional that supports this: ...