Attach additional responsibilities to an object dynamically. Decorators provide a flexible alternative to subclassing for extending functionality.
动态地给一个对象添加一些额外的职责。就增加功能来说,装饰模式相比生成子类更为灵活。
The classes and objects participating in this pattern are:
- defines the interface for objects that can have responsibilities added to them dynamically.
- defines an object to which additional responsibilities can be attached.
- maintains a reference to a Component object and defines an interface that conforms to Component's interface.
- adds responsibilities to the component.
