The Adapter design pattern
The Adapter pattern is another structural design pattern that allows two incompatible interfaces to work together without modifying their existing code. This pattern introduces a wrapper class called the Adapter, which bridges the gap between the interfaces.
Goal
The Adapter design pattern is applicable when we want to use an existing class, but its interface is incompatible with what we want to use it for. Instead of refactoring the class, which could introduce bugs or errors in the existing codebase or even cascade changes to other parts of the system, we can use an Adapter class to make the class’s interface compatible with the Target interface.
The Adapter pattern is handy when we cannot change the Adaptee’s code or do not want to change it.
Design
You can think of the adapter as a power outlet’s universal adapter; you can connect a North American device to a European outlet by connecting it to the adapter and...