Search⌘ K

Adapter Pattern

Explore how the adapter pattern enables classes with incompatible interfaces to work together in JavaScript. Learn to implement this pattern by translating interfaces, making it useful for updating APIs or connecting legacy and new systems.

What is the adapter pattern?

The adapter pattern allows classes that have different interfaces (properties/methods of an object) to work together. It translates the interface for a class to make it compatible with another class.

This pattern is useful if an API is modified or new implementations are added to it. In this case, if the other parts of a system are still using the old API, the adapter pattern will translate the interface so that the two can work together.

As you can see from the diagram above, the client cannot connect to the adaptee ...