Adapter#

The Adapter pattern is a structural design pattern that allows objects with incompatible interfaces to work together. It acts as a bridge between two incompatible interfaces by converting the interface of a class into another interface that a client expects.

In layman’s terms, imagine you have a plug that doesn’t fit into a socket. An adapter is like a device that you can plug into the socket, and then you can plug your plug into the adapter. This way, the plug and socket can work together even though they were not designed to be compatible.

UML Diagram#

+-----------------+      +------------------+
|    Client       |      |  Target          |
|-----------------|      |------------------|
| request()       |      | request()        |
+-----------------+      +------------------+
          |                      ^
          |                      |
          v                      |
+-----------------+      +------------------+
|    Adapter      |      |  Adaptee         |
|-----------------|      |------------------|
| request()       |----->| specificRequest()|
+-----------------+      +------------------+
--- Java Example ---
--- Python Example ---