Skip to main content

ChatGPT Prompt to Recommend the Right Design Pattern

Diagnose code smells and get design pattern recommendations with before/after refactoring, a migration plan, and a testing strategy.

Fill in the placeholders

Edit the values, then copy your finished prompt.

Your Prompt
prompt.txt

                                

What this prompt does

This prompt makes the AI a design patterns expert that diagnoses a [code_smell] and recommends the right pattern to fix it, with full before/after code. You describe the smell, the [pain_points] it causes, your [tech_stack], and your [team_size], and it returns a six-part analysis: a named diagnosis, a recommendation of one or two patterns, a complete before-and-after refactor, a step-by-step implementation guide, trade-offs and warnings, and a testing strategy.

The structure works because it refuses to apply a pattern blindly. It names the specific smell (God Class, Feature Envy, Shotgun Surgery), explains why it is problematic rather than just that it is, and rates how much worse it gets as the codebase grows. It draws recommendations from the creational, structural, and behavioral categories, notes any [framework]-specific implementations, and is explicit about when the pattern becomes over-engineering. Your [team_size] and [additional_consideration] shape the advice, because the wrong abstraction is worse than the smell it replaces.

When to use it

  • You have a God class or tangled conditional and aren't sure which pattern fits
  • You want a before/after refactor that touches every affected file, not just the main class
  • You need a migration plan that won't break production while you refactor
  • You want honest trade-offs, including when a pattern is overkill for your team
  • You are weighing two patterns and need a reasoned comparison
  • You need a testing strategy that would have caught the original smell

Example output

You get a named diagnosis with a severity rating, a recommendation of one or two patterns with reasoning against the alternatives, a complete before-and-after code transformation across all affected files, a step-by-step migration guide, a trade-offs section flagging over-engineering and performance, and a testing strategy with unit and integration tests that pin the new behavior.

Pro tips

  • Paste the actual code or describe [code_smell] concretely; vague smells get vague pattern advice
  • Spell out [pain_points] in terms of real cost ("can't unit test providers") so severity is judged accurately
  • Set [framework] so it surfaces built-ins; Laravel's container already provides some patterns for free
  • Use [additional_consideration] for the constraint that matters, like A/B testing flows per region
  • Match [team_size] honestly, since discoverability advice differs for a solo dev versus a mixed team
  • Push back if the recommendation feels heavy; ask it to justify the pattern against the simpler do-nothing option

Frequently Asked Questions

Will it show me the actual refactored code?
Yes. The before-and-after section shows the complete transformation, including every file that needs to change, not just the main class. It highlights the smell in the original and applies the chosen pattern to the cleaned-up version.
How does it avoid recommending an over-engineered pattern?
The trade-offs section explicitly covers when the pattern becomes over-engineering, its performance implications, and its impact on code discoverability. It is designed to warn you, since the wrong abstraction is often worse than the original code smell.
Does it consider my framework's built-in features?
Yes. Setting the `[framework]` variable prompts it to note framework-specific implementations, such as how Laravel's service container already provides certain patterns, so you do not reinvent something the framework hands you.
Can it recommend a pattern without me knowing which smell I have?
Yes. You describe the problematic code in `[code_smell]` and the pain it causes in `[pain_points]`, and the diagnosis step names the specific smell for you, such as God Class or Feature Envy, before recommending a fix.
Does it help me refactor without breaking production?
The implementation guide provides a step-by-step migration plan covering what to create first, what to modify, how to migrate existing code safely, and how to test each step, so the refactor can ship incrementally rather than as one risky change.
Engr Mejba Ahmed

Need this built for real?

Engr Mejba Ahmed

AI Developer · Software Engineer

I'm Mejba — I design and ship production AI systems, automations, and full-stack apps. If you want this turned into a working solution for your team, let's talk.

More in ChatGPT Prompts for Developers

Engr Mejba Ahmed

Engr Mejba Ahmed

Claude Code Expert · Online

👋

Hey there!

Quick Actions

WhatsApp Instant reply

Chat on WhatsApp

+880 1723 741224 · Instant reply

Popular Questions

Engr Mejba Ahmed is connected
Engr Mejba Ahmed is typing...
Engr Mejba Ahmed avatar

✉ Want me to follow up? Drop your email

Engr Mejba Ahmed avatar

📞 Connect Directly

Choose how you'd like to reach me

WhatsApp

+880 1723 741224

Email

[email protected]

✓ Details sent! I'll get back to you shortly.

Powered by OpenAI

335+

Blog Posts

25

AI Courses

63

Projects

Services & Expertise

Pricing & Process

Learning & Resources

Connect & Support