You are staring at a class that has grown three responsibilities and a name that ends in Manager. You know a pattern would clean it up, but you cannot remember which one fits or how it should look in your language. These five Gemini prompts walk you from a fuzzy problem to a named pattern and a concrete draft.
What to know before you paste
- Gemini handles long context well, so paste the whole file. It needs to see how the classes already call each other before it suggests a pattern.
- Name your language and version up front. “[language]” alone can pull idioms from a sibling language and give you code that will not compile.
- On a fast model tier, ask for one pattern at a time. Save the compare-several prompt for a reasoning-heavy tier that can weigh trade-offs.
The prompts
1. Match the problem to a pattern
Here is a description of my problem: [problem description]. The language is [language] and the codebase is [codebase style]. Suggest the two design patterns that fit best, name each one, and explain in three sentences why it fits. Then tell me which of the two you would pick and why.
What it does: Turns a symptom into a short list of candidate patterns with a clear recommendation.
How to use: replace [problem description], [language], and [codebase style] (for example, “plain classes, no framework”).
2. Sketch the classes in plain text
Draw the structure of the [pattern name] pattern for my case: [case summary]. Use a text outline, not an image. Show each class, its responsibilities, and the relationships between them. Mark which parts are fixed by the pattern and which parts I get to decide for [my domain].
What it does: Gives you a buildable outline before you write a single line of code.
How to use: replace [pattern name], [case summary], and [my domain] with your actual problem area.
3. Refactor toward the pattern
Refactor this code toward the [pattern name] pattern: [paste code]. Do it in small steps. After each step, show the code and one sentence on what changed. Keep behavior identical, and stop before you rename anything public.
What it does: Applies a pattern incrementally so you can review and test between steps.
How to use: replace [pattern name] and [paste code]; ask for more steps if the diff is too large to check at once.
4. Compare two patterns head to head
Compare [pattern A] and [pattern B] for this situation: [situation]. Give me a small table with rows for flexibility, complexity, and testability. Then state which one to use if the codebase will [future change], and which to use if it will not.
What it does: Keeps you from reaching for the fancier pattern by default.
How to use: replace [pattern A], [pattern B], [situation], and [future change] with your real constraints.
5. Name the pattern already hiding in the code
Look at this code and tell me which design pattern it is already using, even if the author never named it: [paste code]. Point to the lines that show the pattern, and note any place where the pattern is broken or half-applied. Suggest the smallest fix for each break.
What it does: Reveals the pattern in existing code and where it leaks.
How to use: replace [paste code]; if it is a large file, paste the two or three classes that interact most.
FAQ
Do I need to know patterns before using these prompts?
No. The first prompt asks Gemini to suggest patterns by name, and the second turns the choice into a structure you can follow. You learn the pattern as you build it.
Why not just ask for the finished refactor in one shot?
Large one-shot rewrites are hard to review and easy to break. Stepwise refactoring keeps behavior the same and lets you test between changes.
Will the suggested pattern fit my language’s idioms?
Only if you name the language and version. A pattern that reads well in one language can be awkward in another, so always state where the code will run.
What if two patterns seem equally good?
Use the compare prompt and decide by what will change later, not by what looks elegant now. Pick the simpler one when future change is uncertain.
Can I use these prompts for an existing legacy file?
Yes, and the last prompt is built for it. It finds the pattern already present so you can fix it instead of rewriting from zero.
These prompts are free to use. Copy them, tweak the [variables], and ship something.