I Help You
Programming

Adapter Design Pattern

The Adapter pattern is a structural design pattern that lets classes with incompatible interfaces work together. An adapter wraps an existing class and translates calls from the interface the client expects into calls the existing class understands.

It is like a travel plug adapter: neither the socket nor the plug changes. Adapters are often used to integrate third-party libraries or legacy code without modifying them.

Example
interface PaymentGateway { void pay(double amount); }

class LegacyBankApi { void makeTransfer(long paise) { /* ... */ } }

class BankAdapter implements PaymentGateway {
	private final LegacyBankApi bank = new LegacyBankApi();
	public void pay(double amount) { bank.makeTransfer(Math.round(amount * 100)); }
}