DEV Community

Alailson
Alailson

Posted on

How to use Adapter Pattern with express.js

The article will answer 3 following questions for you to start using the Adapter Pattern in your projects and the last one topic i will tell about my own experiences with Adapter Pattern.

  1. What is an Adapter Pattern?
  2. How to implement?
  3. When is it recommended?
  4. how i use Adapter Pattern with express.js (personal opinion)

1.. What is an Adapter Pattern?.
Adapter is a structural design pattern, which allows incompatible objects to collaborate. The Adapter acts as a wrapper between two objects. It catches calls for one object and transforms them to format and interface recognizable by the second object.

[fonts] - https://refactoring.guru/design-patterns/adapter/typescript/example

2.. How to implement Adapter Pattern?.
Alt Text
[fonts] - https://www.youtube.com/watch?v=beU4i949YXU
3.. When is it recommended?
it's very often used in systems based on some legacy code. In such cases,
Adapters make legacy code work with modern classes.

4.. How i use Adapter Pattern with express.js (personal opinion).
I started to use Adapter Pattern 3 months ago in all my projects with express.js, flask(Python) and fiber(go).
My motivation to use Adapters.
i want to isolate my code from frameworks, it means i don’t wanna make a project that depends totally from one single framework. a framework can get old, can be replaced by one better and I can adapt my project to a new framework without having to rewrite all the code again.
Alt Text

Top comments (0)