Adapter Pattern Guide
Use the adapter pattern to bridge incompatible interfaces, enabling classes to work together that otherwise could not. Essential for integrating third-party libraries, legacy systems, and external APIs.
Usage
Ask about creating adapters for third-party integrations, choosing between class and object adapters, or refactoring tightly coupled code with adapters.
Examples
- "How do I adapt a third-party payment SDK to my payment interface?"
- "What is the difference between class adapter and object adapter?"
- "Help me create an adapter for migrating from one ORM to another"
Guidelines
- Adapters should be thin — only translate interfaces, not add logic
- Prefer object adapters (composition) over class adapters (inheritance)
- Use adapters at system boundaries to isolate external dependencies
- Name adapters clearly to indicate what they adapt from and to
- Adapters are ideal for the anti-corruption layer in DDD