Adapter is a piece of code with only one function, to allow an interface of another class to be used as another, so you dont have to modify the existing class. It just simply and silently sits in the middle of two or more modules.

One of the common usages is ORM adapters, that let you switch between database types without changing any of the app’s code. Utilizing this pattern, switching from Mongo to MySQL becomes trivial. That said, lets see how to implement one.

Say you are developing something with no db access, but want to be able to work with it just as you would as if you had one. Have no fear, adapter is here! We are going to create a localstorage adapter to show how it is done.


U see how easy this was 🙂 Now, to be trully sure all our adapters implement the same interface, you could use Typescript or implement a prototype on those adapters that will throw errors or warn you if something is not handled.

Next, the Bridge pattern!