DELAPARRA
Index
Color
NL
Category: Design patterns

Adapter

Explained by Updated

What is Adapter?

Adapter: Convert the interface of a class into another interface that clients expect — making incompatible interfaces work together. The Adapter pattern wraps a class so it offers the interface your code expects. It is the software version of a travel plug: the socket and the plug stay the same, and the adapter sits in between.

Definition source Coders Lingo, CC BY 4.0

Frequently asked questions about Adapter

How is Adapter used in practice?

You use it all the time when integrating external services. Your application defines a small interface, such as PaymentGateway with a charge() method. An adapter translates that into Mollie's or Stripe's specific API calls.

What should you keep in mind with Adapter?

The benefit shows up later. If you switch payment providers, you write one new adapter and leave the rest of the code alone. Testing also gets easier, because you can swap in a fake adapter that never contacts a real service. Keep adapters thin. They translate between two interfaces and should not contain business rules of their own.

At a glance

CategoryDesign patterns
Explained by
Updated

More Design patterns terms

All terms starting with A

Skills

Download all skills (zip)

Manuals

Related services

Need any help?

Stuck on one of these in your own project? Tell me what you are working on and I will tell you how I would approach it.