Extract Decorator

Decorators can be used to lay new concerns on top of existing objects with- out modifying existing classes. They combine best with small classes with few methods, and make the most sense when modifying the behavior of existing methods, rather than adding new methods.

  1. Extract a new decorator class, starting with the alternative behavior.
  2. Compose the decorator in the original class.
  3. Move state specific to the alternate behavior into the decorator.
  4. Invert control, applying the decorator to the original class from its con- tainer, rather than composing the decorator from the original class.

It will be difficult to make use of decorators unless your application is following Composition Over Inheritance⭐.