The main research in this paper is about the implementation of the relevant contents of the Adapter mode by python, and the concrete implementation of the code is as follows. There are two implementations of the

Adapter pattern, one of which is a class style. The principle of

 # # power adapter is to understand it, will have not compatible interface can work this is # class implementation # example # if a socket output pin is 3 feet, while the lamp is in need of two sockets, now you need to achieve a Adapter #Adaptee class socket (socket adapter object): def Trigle (self): print'power supply'#target class tableLamp (object): def needTwo (self): pass #adapter class Adapter (tableLamp, socket): def needTwo (self): self.Trigle (#client) if __name__=='__main__' (lamp.needTwo): lamp=Adapter (



second is the object mode. This is the

 # object realization mode of class socket (object): def Trigle (self): print'power supply over'#target class tableLamp (object): def needTwo (self): pass #adapter class Adapter (tableLamp): def __init__ (self, Socket): self.socket=Socket def needTwo (self): self.socket.Trigle (#client) if __name__=='__main__': plug=socket (lamp=Adapter) (plug) (lamp.needTwo) 

you might be interested in this article: Adapter

This concludes the body part

This paper fixed link: | Script Home | +Copy Link

Article reprint please specify:Python implementation of the Adapter schema instance code | Script Home

You may also be interested in these articles!