Decoration in a nutshell

The decorator pattern is a powerful design pattern that can be leveraged when building objects at runtime, where the final object has features that are defined over time, and where only the final outcome matters:

  1. Identify in your program an object that can or should be abstracted with this pattern
  2. Define the base protocol for your object (in our case, that was Burger)
  3. Define the decorator interface, in our case the BurgerDecorator, and ensure it conforms to the decorator's interface (Burger)
  4. Leverage protocol extensions to provide the default values for the decorator
  5. Provide at least one constructor or method to decorate the base object (.init(Burger) or .decorate(Burger))
  6. Build your decorating features out of the decorator's interface
  7. Use your decorator objects to build (over time and in multiple steps) your decorated objects out of base implementations