Book Notes

The Decorator Pattern: attaches additional responsibilities to an object dynamically. Decorators provide a flexible alternative to subclassing for extending functionality.

  • Decorators have the same supertype as the objects they decorate.
  • You can use one or more decorators to wrap an object.
  • The decorator adds its own behavior before and/or after delegating to the object it decorates to do the rest of the job.

Design Pattern:

Example