liuxuhelloworld's notebook

The decorator pattern attaches additional responsibilities to an object dynamically. Decorators provide a flexible alternative to subclassing for extending functionality.

decorator-1

Once you know the techniques of decorating, you’ll be able to give your (or someone else’s) objects new responsibilities without making any code changes to the underlying classes.

Decorator具备以下特性:

应用实例:

decorator-2

decorator-3

decorator-4