What is an Adapter Pattern?
The Adapter Pattern connects two incompatible objects by exposing an interface compatible with the Client. The object refers to a class, web service, REST API, process, or physical device depending upon your context.
Consider a C# Web Application displaying Weather Updates on its landing by utilizing the third-party REST API.
In this application, there are three participating objects in the Adapter Pattern:
- A Weather REST API (Adaptee) has the functionality of weather updates. The Weather REST API only understands JSON.
- The C# MVC Web Application (Client) displays weather updates on its landing page using the Weather Web Service.
- The Adapter enables the Client to utilize the Adaptee functionality. It does that by doing two things:
- It converts the Client's input to the format acceptable to Adaptee i.e. JSON to C# Object(s).
- It converts the Adaptee's output to the format acceptable to the Client i.e. C# Object(s) to JSON.