Skip to main content
Practice Problems

What is Adapter design pattern?

javascript
// Old system class OldPaymentGateway { processPayment(amount) { console.log(`Processing $${amount}`); } } // New interface needed class PaymentAdapter { constructor(gateway) { this.gateway = gateway; } pay(amount, currency) { // Adapt old interface to new const converted = this.convertCurrency(amount, currency); this.gateway.processPayment(converted); } convertCurrency(amount, currency) { // Conversion logic return amount; } } // Usage const oldGateway = new OldPaymentGateway(); const adapter = new PaymentAdapter(oldGateway); adapter.pay(100, "USD"); // Works with new interface!

Short Answer

Interview ready
Premium

A concise answer to help you respond confidently on this topic during an interview.

Finished reading?
Practice Problems