Structural PatternsAdapter PatternHard⏱️ ~3 min

When to Use Adapter Pattern vs Alternatives

The Adapter Pattern is not always the right choice. Understanding when to use it versus alternatives, and when it becomes overkill, is crucial for clean design decisions.

Use Adapter Pattern When

1. Interface Incompatibility Exists: You have an existing class with useful functionality but its interface does not match what your client expects. Modifying the existing class is not possible (third-party library) or not desirable (violates Open-Closed Principle).

2. Reusing Legacy Code: You need to integrate legacy systems into new architectures without rewriting them. The legacy system works correctly but has outdated interfaces.

3. Multiple Incompatible Implementations: You need to support multiple third-party services (like different payment gateways, notification services, or storage providers) with different APIs through a uniform interface.

Avoid Adapter Pattern When

1. You Control Both Interfaces: If you own both the client and the service code, refactor to use a common interface directly rather than adding adapter layers. The adapter adds unnecessary indirection.

2. Simple Wrapping Suffices: If you only need to add behavior without interface translation, use the Decorator Pattern instead. Adapter focuses on interface conversion, not behavior enhancement.

3. Complex Translation Logic: If the translation between interfaces requires substantial business logic or complex transformations, the adapter becomes a God Object. Consider using a Facade or a dedicated service layer instead.

Adapter vs Similar Patterns

Adapter Pattern
Converts existing interface to expected interface. Applied retroactively to incompatible classes.
vs
Bridge Pattern
Separates abstraction from implementation. Designed upfront to allow independent variation of both.
Adapter Pattern
Makes interfaces compatible. No new behavior added, only translation.
vs
Decorator Pattern
Adds new responsibilities to objects. Same interface before and after decoration.
Adapter Pattern
Single interface conversion. One-to-one mapping between methods.
vs
Facade Pattern
Simplifies complex subsystem. Many-to-one mapping, hides complexity.

When Adapter Becomes Overkill

Scenario 1: Trivial Conversion

If the adaptation only renames a method with identical signatures, a simple wrapper function may suffice. Creating full adapter classes adds unnecessary ceremony for one-line delegations.

Scenario 2: Single Use Case

If you only have one incompatible class and one client, directly calling the incompatible class may be acceptable. Document the interface mismatch but avoid premature abstraction. However, if future incompatible classes are likely, use the adapter from the start.

Scenario 3: Performance-Critical Path

In high-frequency, low-latency systems (like HFT - High-Frequency Trading), the indirection layer of adapters may introduce unacceptable overhead. Profile first, but if confirmed, consider direct integration with performance-critical components.

Interview Tip: When asked to justify your design, explain not just why you chose Adapter, but also why you rejected alternatives. Discuss trade-offs explicitly: maintainability vs performance, flexibility vs simplicity.
💡 Key Takeaways
Use Adapter for interface incompatibility with third-party or legacy code
Avoid Adapter when you control both interfaces or need behavior enhancement
Bridge is designed upfront; Adapter is applied retroactively
Facade simplifies many interfaces; Adapter converts one interface
Consider direct integration if adapter is overkill for single use cases
📌 Examples
1Use Adapter for multiple payment gateways with different APIs
2Avoid Adapter if renaming one method in code you own
3Use Facade instead when simplifying complex subsystem with many classes
← Back to Adapter Pattern Overview
When to Use Adapter Pattern vs Alternatives | Adapter Pattern - System Overflow