Adapter Design Pattern
Adapter Design Pattern The Adapter design pattern is used to allow two incompatible interfaces to work together. It involves creating a class (the adapter) that acts as a bridge between two interfaces, converting the interface of one class into another interface that clients expect. In other words, it helps to make different classes or components work together seamlessly. Here’s an example of implementing the Adapter pattern in Python: # Adaptee class LegacyRectangle: def draw( self , x1, y1, x2, y2): print ( f"Drawing a legacy rectangle: ( { x1 } , { y1 } ), ( { x2 } , { y2 } )" ) # Target interface class Shape: def draw( self ): pass # Adapter class RectangleAdapter(Shape): def __init__ ( self , legacy_rectangle): self .legacy_rectangle = legacy_rectangle def draw( self ): x1, y1, x2, y2 = 0 , 0 , 10 , 20 self .legacy_rectangle.draw(x1, y1, x2, y2) def main(): legacy_rectangle = Legac...