code def repeat(num):def my_decorator(func):def wrapper(*args, **kwargs):for i in range(num):print('wrapper of decorator {}'.format(i))func(*args, **kwargs)return wrapperreturn my_decorator@repeat(4)
装饰者模式的uml 通过继承和组合的方式来设计类的修饰作用在继承的基础上,通过引用让对象具有多重修饰(拥有其他子类的方法)的特性。 这个类图是《Head first 设计模式》上的例子 装饰者的魔力主要在于CondimentDecorator的身上,它是抽象的装饰者类。继承CondimentDecorator在构造方法上都引用了Baverage抽象类。 抽象的Beverage类 pu