Created
February 27, 2022 18:01
-
-
Save adriatikgashi/58cfb9d9dc8f990e8f8f8a95c9e7ac8c 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 Shipping { | |
func getCost(forOrder order: Order) -> Double | |
} | |
class GroundShipping: Shipping { | |
func getCost(forOrder order: Order) -> Double { | |
if order.getTotal() > 100 { | |
return 0 | |
} | |
// $1.5 per kilogram, but $10 minimum | |
return max(10, order.getTotalWeight() * 1.5) | |
} | |
} | |
class AirShipping: Shipping { | |
func getCost(forOrder order: Order) -> Double { | |
return max(20, getTotalWeight() * 3) | |
} | |
} | |
struct Order { | |
let lineItems: [String] | |
let shipping: Shipping | |
func getShippingCost() -> Double { | |
return shipping.getCost(forOrder: self) | |
} | |
func getTotal() -> Double { | |
// calculate the total | |
return 0.0 | |
} | |
func getTotalWeight() -> Double { | |
// calculate the total weight | |
return 0.0 | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment