Bridge between incompatible interfaces
In a nutshell, the adapter Design Pattern is a powerful tool for building flexible and future-proof software by creating bridges between incompatible interfaces.
# Target interface: the interface the client expects
class Target:
def request(self):
pass
# Adaptee: the existing class with a different interface
class Adaptee:
def specific_request(self):
print("Adaptee's specific request")
# Adapter: bridges the gap between Target and Adaptee
class Adapter(Target):
def __init__(self, adaptee):
self.adaptee = adaptee
def request(self):
self.adaptee.specific_request()
# Client code
client = Client()
adapter = Adapter(Adaptee())
client.do_something(adapter) # Client interacts with the adapter seamlessly