图4显示了装饰器模式的类图。
装饰器模式的优点是可以轻松地同时跟踪库的多个装饰器。
An advantage of the decorator pattern is that you can easily tack on more than one decorator to the base at a time.
装饰器模式动态地将责任附加到对象上。若要扩展功能,装饰者提供了比继承更有弹性的替代方案。
Decorator Pattern Attaches additional responsibilities to an object dynamically. Decorators provide a flexible alternative to sub classing for extending functionality.
应用推荐