/ Design Patterns / Structural patterns / Adapter Adapter Design Pattern in Python Back to Adapter description """ Convert the interface of a class into another interface clients expect. Adapter lets classes work together that couldn't otherwise because of incompatible interfaces. """ import abc class Target(metaclass=abc.ABCMeta): """ Define the domain-specific interface that Client uses. """ def __init__(self): self._adaptee = Adaptee() @abc.abstractmethod def request(self): pass class 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): pass def main(): adapter = Adapter() adapter.request() if __name__ == "__main__": main() Support our free website and own the eBook! 22 design patterns and 8 principles explained in depth 406 well-structured, easy to read, jargon-free pages 228 clear and helpful illustrations and diagrams An archive with code examples in 4 languages All devices supported: EPUB/MOBI/PDF formats Learn more...