Adapter
Explore how to use the adapter design pattern in Python to unify incompatible interfaces. Understand methods of adaptation using inheritance and composition, and when to apply each approach to maintain clean and flexible code.
The adapter pattern is a structural pattern and probably one of the simplest design patterns there are, as well as being one of the most useful ones at the same time.
Also known as a wrapper, this pattern solves the problem of adapting interfaces of two or more objects that are not compatible.
Usage of the adapter pattern
We typically encounter a situation where part of our code works with a model or set of classes that were polymorphic with respect to a method.
Working with an example
For example, if there are multiple objects for retrieving data with a fetch() method, then we want to maintain this interface so we ...