December 2018
Intermediate to advanced
414 pages
10h 19m
English
As you may have noticed, most of the decorator interfaces are the same and can be abstracted as (Burger) -> Burger functions. All the constructors take Burger as the first parameter and return a new instance of their class, which is BurgerDecorator, which in turn is a Burger.
It is possible to add a method to the toppings enum so that it can decorate a Burger:
extension Topping { func decorate(burger: Burger) -> WithTopping { return WithTopping(burger: burger, topping: self) }}// Topping.ketchup.decorate(burger: burger)
It would technically be possible to gather all the functions that decorate a burger, and finally apply them to a burger:
var decorators = [(Burger) -> Burger]decorators.append(Topping.ketchup.decorate) ...
Read now
Unlock full access