Adapter pattern
The adapter design pattern enables a handshake between two incompatible interfaces. Here, the incompatible interface of a class or a library is transformed into the one expected by your client code. This transformation is accomplished by an adapter class. The other class with a different interface than what the client expects is often referred to as an adaptee.
There are two broad categories of adapter pattern, namely a class adapter pattern and an object adapter pattern. In the former, the adapter inherits from the adaptee. It is possible to implement a class adapter in Python, as the language supports multiple inheritance. However, it is better to choose object composition (has a relationship) over inheritance. In the object adapter ...
Get Learning Python Application Development now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.