Adapter Design Pattern Explained

Adapter converts the interface of one class into another interface that calling code expects, letting otherwise incompatible interfaces work together.

Published November 12, 2026

The Adapter pattern converts one interface into another that a client expects, letting incompatible classes work together. It is like a plug adapter for a foreign socket.

The concept

The adapter wraps the incompatible object (the adaptee) and exposes the target interface, translating calls and data formats.

Common uses: wrapping third-party SDKs so your code depends on your own interface and can switch vendors.

Translate between interfaces

pay()makeCharge()Clientexpects pay()AdaptertranslatesVendor SDKmakeCharge()
Client sees the target interface only.

Practical examples

Wrap a vendor SDK

class StripeAdapter {
  constructor(stripe) { this.stripe = stripe }
  pay(amountRupees) { return this.stripe.charges.create({ amount: amountRupees * 100, currency: 'inr' }) }
}

Swap vendors

const gateway = useRazorpay ? new RazorpayAdapter(rzp) : new StripeAdapter(stripe)
gateway.pay(499)

Data shape adapter

const toUser = (api) => ({ id: api.user_id, name: api.full_name })

Common mistakes

  • Leaking vendor types through the adapter.
  • Adapting more than needed.
  • Putting business logic in the adapter.

Key takeaways

  • Make incompatible interfaces compatible.
  • Isolate third-party code.
  • Keep adapters thin.

FAQ

Adapter vs Facade?

Adapter changes an interface; Facade simplifies a whole subsystem.

Adapter vs Decorator?

Decorators keep the same interface and add behaviour.

More General articles