design patterns
Adapter
The Adapter pattern converts the interface of a class into another interface that clients expect. It lets classes work together that could not otherwise because of incompatible interfaces. The key participants are the Target (the interface the client expects), Adaptee (the existing class with an incompatible interface), and Adapter (converts the Adaptee's interface to the Target interface). Think of a power plug adapter when traveling abroad: your device's plug (Adaptee) does not fit the foreign outlet (Target), so you use an adapter that bridges the two. Use Adapter when you want to use an existing class but its interface does not match the one you need, or when you want to create a reusable class that cooperates with unrelated classes that have incompatible interfaces.
Use Cases
- •Integrating third-party libraries with different APIs
- •Wrapping legacy code to work with modern interfaces
- •Normalizing data from different sources into a unified format
- •Making incompatible classes collaborate in a system