The Adapter pattern is useful when integrating third-party libraries because it lets you translate an external library's interface into the interface your application already expects, without modifying either the library or your existing code.
If your application defines a PaymentProcessor interface but wants to use a third-party StripeClient with a different method signature, a StripeAdapter can implement PaymentProcessor and translate calls into the StripeClient API underneath.
public class StripeAdapterDemo {
// Your application's own interface
interface PaymentProcessor {
boolean charge(String customerId, double amountInRupees);
}
// Third-party library you cannot change (different names and units)
static class StripeClient {
String createCharge(long amountInPaise, String currency, String customer) {
return "ch_" + customer + "_" + amountInPaise + currency;
}
}
// The adapter translates between the two
static class StripeAdapter implements PaymentProcessor {
private final StripeClient stripe = new StripeClient();
public boolean charge(String customerId, double amountInRupees) {
long paise = Math.round(amountInRupees * 100);
String chargeId = stripe.createCharge(paise, "inr", customerId);
System.out.println("Stripe charge id: " + chargeId);
return chargeId != null;
}
}
public static void main(String[] args) {
PaymentProcessor processor = new StripeAdapter(); // swap provider here only
System.out.println("Success: " + processor.charge("cust42", 499.50));
}
}Stripe charge id: ch_cust42_49950inr
Success: true
A concise interview answer is
Adapter is useful for third-party integration because it lets me translate an external library's interface into the interface my application already uses, without modifying the library or scattering library-specific calls throughout my codebase — if the library changes or gets replaced, only the adapter needs updating.
Last updated: 1 November 2026
Previous question: What are the two types of adapters (class and object adapters), and how do they differ?
Next question: What is the Bridge pattern and how does it decouple abstraction from implementation?