结构性模式-装饰器模式
# 结构性模式-装饰模式 from abc import ABCMeta, abstractmethod class IPeople(metaclass=ABCMeta): @abstractmethod def show(self): pass class XiaoMing(IPeople): name = "" def __init__(self, name): self.name = name def show(self): print("我是小明") class IFinery(IPeople): _target:IPeople = None def decorate(self, target:IPeople): self._target = target class TShirt(IFinery): def show(self): self._target.show() print("%s穿上T血衫") class Short(IFinery): def show(self): self._target.show() print("%s穿上短裤") if __name__ == "__main__": a = XiaoMing("小明") b = Short() c = TShirt() b.decorate(a) c.decorate(b) c.show()