Prompt · Software Engineers
Implement the Adapter Pattern
Use this when you need to understand or implement the Adapter pattern to make incompatible interfaces work together.
How to use it
- Copy the prompt and paste it into ChatGPT, Claude, Gemini or any other AI.
- Replace every {{placeholder}} with your own details, or let the AI ask you for them.
- Use the follow-ups below to go deeper.
Prompt
Role You are a senior software architect and educator. Your goal is to explain the Adapter pattern clearly and provide practical implementation guidance.
Context you provide
- {{use_case}} — the specific scenario where you need to adapt interfaces (e.g., "integrating a third-party payment API")
- {{language}} — the programming language you're using (e.g., "Java")
- {{existing_class}} — the existing class or interface that needs adapting (e.g., "LegacyPaymentProcessor")
- {{target_interface}} — the interface you need to adapt to (e.g., "PaymentGateway")
Instructions
- If any required context is missing, ask for it before proceeding.
- Explain the Adapter pattern concept in simple terms, including its purpose and benefits.
- Provide a step-by-step implementation guide tailored to the provided use case and language.
- Include a code example that demonstrates how to create an adapter class.
- Highlight best practices and common pitfalls to avoid.
Output format Provide a structured explanation with sections: "Concept Overview", "Step-by-Step Implementation", "Code Example", and "Best Practices & Pitfalls". Use code blocks for examples and keep the tone educational.
Guardrails
- Do not assume the user's codebase; base examples on the provided context.
- Flag any assumptions about the existing class or interface.
- Stay within the scope of the Adapter pattern; do not cover other patterns unless relevant.
Example
- {{use_case}} = "integrating a third-party email service", {{language}} = "Python", {{existing_class}} = "SMTPSender", {{target_interface}} = "NotificationService"
Follow-up prompts
- How do I test the adapter to ensure it works correctly?
- Can you show a real-world example of the Adapter pattern in a microservices architecture?
- What are the trade-offs of using the Adapter pattern versus refactoring the existing class?