StructuralverifiedVerified

Adapter

Converts the interface of a class into another interface that clients expect, allowing incompatible interfaces to work together.

Coming Soon

errorWhat Problem Does the Adapter Pattern Solve?

Third-party libraries, legacy systems, and external APIs rarely match the interface your application expects. Rewriting the external code is often impossible, and scattering conversion logic throughout the codebase creates fragile, duplicated coupling to specific implementations.

check_circleHow the Adapter Pattern Works

Create an Adapter class that wraps the incompatible object and exposes the interface the client expects. The client talks to the adapter, which translates each call into the corresponding method on the adaptee. The adaptee never changes, and the client never knows an adapter exists.

Adapter Pattern Architecture

hourglass_empty

Rendering diagram...

Implementation by Language

lightbulb

Adapter Pattern in the Real World

A travel power adapter lets your American laptop plug (client) work in a European wall socket (adaptee) without modifying either. The adapter speaks both “languages”, translating the two-pin plug to the two-round-pin socket, making them interoperable without any changes on either side.

Frequently Asked Questions

helpWhat is the difference between Adapter and Facade?

Adapter converts one interface to match another, making incompatible classes work together. Facade simplifies a complex subsystem by providing a unified, easier interface. Adapter changes the interface shape; Facade reduces interface complexity.

helpShould I use class-based or object-based Adapter in TypeScript?

Prefer object-based (composition) Adapter in TypeScript. Class-based Adapter uses multiple inheritance, which TypeScript doesn't support natively. Composition is also more flexible — you can swap the adaptee at runtime and test with mocks more easily.