We use analytics cookies.We use cookies to analyze site traffic and improve your experience.
Loading...
System Design Masterclass · Microservices Architecture
Free preview: the first 2 parts of this 8-part lesson.
Already bought the course? Sign in to read the whole lesson.
this lesson is part of
System Design Masterclass
Unlock this lesson and the 751 other paid lessons
$25 once, by PayPal
See the System Design courseread the rest of this lesson in
System Design Masterclass
Unlock this lesson and the 751 other paid lessons
$25 once, by PayPal
See the System Design coursein Microservices Architecture
This lesson is part of the full System Design Masterclass. Unlock it along with 769 other lessons for a one-time payment.
One-time payment by card or PayPal
Get Lifetime AccessOne-time payment: UPI, card or netbanking
Get Lifetime Access18 Foundation lessons are free, no payment needed. Try them now
It is easy and good
“It is really nice and good Please join the course”
You're integrating with a third-party payment gateway. Your system expects a processPayment(amount, currency, cardToken) method. The gateway's SDK offers initiateTransaction({ txn_amount: number, txn_currency: string, payment_instrument: { type: string, token: string } }). Completely different shapes.
You have two choices: rewrite your entire payment interface to match the gateway's API (and then rewrite it again when you switch gateways), or create a thin translation layer that converts your interface to theirs. That translation layer is an Adapter.
You've used adapters your whole life without thinking about it. A power adapter lets your US laptop plug into a European outlet. A USB-C to HDMI adapter lets your phone connect to a TV. The adapter doesn't change what either device does, it just translates between two incompatible interfaces.
The Adapter pattern converts the interface of a class into another interface that clients expect. It lets classes work together that couldn't otherwise because of incompatible interfaces.
| Component | Role |
|---|---|
| Target | The interface your code expects |
| Adaptee | The existing class with an incompatible interface |
| Adapter | Wraps the adaptee and translates calls from target to adaptee |
The adapter implements the target interface and internally delegates to the adaptee, translating parameters, response formats, and error handling as needed.