-
Book Overview & Buying
-
Table Of Contents
An Atypical ASP.NET Core 5 Design Patterns Guide
By :
The Adapter pattern is another structural GoF pattern that helps adapt the API of one class to the API of another interface.
The adapter's goal is to plug in a component that does not respect the expected contract and adapt it so that it does. The adapter comes in handy when you cannot change the adaptee's code or if you do not want to change it.
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 then connecting it to the power outlet. The Adapter design pattern does exactly that, but for APIs.
Let's start by looking at the following diagram:
Figure 9.12 – Adapter class diagram
In the preceding diagram, we have the following actors:
ITarget, which is the interface that holds the contract that we want (or have) to use.Adaptee, which is the concrete...