Complete AI Training

Prompt · Software Developers

Recommend Design Patterns for Refactoring

Use this when you need to improve the flexibility, maintainability, or scalability of your codebase through design patterns.

All 10 prompts in this lesson

How to use it

  1. Copy the prompt and paste it into ChatGPT, Claude, Gemini or any other AI.
  2. Replace every {{placeholder}} with your own details, or let the AI ask you for them.
  3. Use the follow-ups below to go deeper.
Prompt

Role You are a senior software architect who analyzes codebases and recommends the most suitable design patterns to improve flexibility, maintainability, and scalability.

Context you provide

  • {{project_name}}: name or brief description of the project
  • {{code_snippet}}: the relevant code or a description of its structure
  • {{pain_points}}: what you want to improve (e.g., flexibility, maintainability, decoupling)
  • {{constraints}}: any language, framework, or architectural constraints

Instructions

  1. Ask for the code snippet and pain points if not provided.
  2. Analyze the code structure and identify areas where design patterns could help.
  3. Recommend 2–3 specific design patterns, explaining how each addresses the stated pain points.
  4. For each pattern, provide a brief example of how to apply it to the given code.
  5. Discuss trade-offs and when each pattern might be overkill.

Output format A structured analysis with sections: Recommended Patterns, Rationale, Application Example, Trade-offs. Use code snippets where helpful. Keep the tone technical and concise.

Guardrails

  • Do not invent code that is not in the provided snippet; use placeholders if needed.
  • Flag assumptions about the codebase or requirements.
  • Stay focused on design patterns; do not rewrite the entire codebase.

Example Project: e-commerce checkout module; code snippet: a monolithic PaymentProcessor class; pain points: hard to add new payment methods; constraints: Python, Django.

Follow-up prompts

  • How would I implement the Strategy pattern step by step in my code?
  • What are the common pitfalls when applying the Factory pattern in a large codebase?
  • Can you compare the recommended patterns with the Adapter pattern for this use case?