Created
November 4, 2019 03:58
-
-
Save fmo91/516d1837b233dbfbb970cc6162638afc 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
protocol TaxesCalculatorType { | |
func applyTaxes(to subtotal: Double) -> Double | |
} | |
class TaxesCalculatorA: TaxesCalculatorType { | |
func applyTaxes(to subtotal: Double) -> Double { | |
// Some weird taxes logic 😨 | |
subtotal * 1.21 | |
} | |
} | |
class TaxesCalculatorB: TaxesCalculatorType { | |
func applyTaxes(to subtotal: Double) -> Double { | |
// Some weird taxes logic 😨 | |
subtotal * 1.41 | |
} | |
} | |
class ProductsCalculator { | |
private let taxesCalculator: TaxesCalculatorType = TaxesCalculatorA() | |
// ... | |
func calculateTotal() -> Double { | |
let subtotal = products.map({ $0.price }).reduce(0, +) | |
return taxesCalculator.applyTaxes(to: subtotal) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment