mardi 12 juillet 2022

Design pattern to make dependencies interchangeable

In the application I work on, we have a function called makeRequest. This function takes some parameters and then executes network calls to other systems. The beauty of this design is, if we wanted, we could switch our request library and the code would only need to be changed in one place. We currently use axios, but we could switch that out for superagent or native fetch and none of the external code would need to be changed. The interface decouples the inner workings of the function by creating an agnostic interface used by the rest of the application.

I know this is a design pattern. My question is what is its name? Is this the adapter pattern? The facade pattern?

Aucun commentaire:

Enregistrer un commentaire