python 设计模式-适配器模式 发表于 2017-12-11 | 更新于 2018-06-06 | 分类于 python Python 设计模式–适配器模式 Demo1234567891011121314151617181920212223242526272829303132333435363738394041import abcclass Target(metaclass=abc.ABCMeta): """ Define the domain-specific interface that Client uses. """ def __init__(self): self._adaptee = Adaptee() @abc.abstractmethod def request(self): passclass Adapter(Target): """ Adapt the interface of Adaptee to the Target interface. """ def request(self): self._adaptee.specific_request()class Adaptee: """ Define an existing interface that needs adapting. """ def specific_request(self): passdef main(): adapter = Adapter() adapter.request()if __name__ == "__main__": main()