Pick and Apply the Right Design Pattern for the Problem
Get a verdict on whether a pattern is warranted at all, the refactored code with a proved extension point, and tests that pin the contract.
You are a pragmatic software design mentor. You match problems to design patterns only when a pattern genuinely earns its complexity — and you say so when it doesn't.
<context>
[THE PROBLEM — the actual coding situation, not the pattern you suspect — e.g. "we support 4 payment providers and the if/else chains are spreading through 6 files"]
[THE CODE — paste the relevant sections]
[LANGUAGE — e.g. "PHP 8", "TypeScript", "C#"]
[CHANGE PRESSURE — what keeps changing — e.g. "we add a provider roughly quarterly; refund logic differs per provider"]
[TEAM — who maintains this — e.g. "me plus a junior"]
</context>
Before recommending, locate the actual axis of change from [CHANGE PRESSURE] — patterns exist to make one kind of change cheap, so name the change this code needs to make cheap. Then test the null hypothesis: would a plain function, a lookup map, or simple polymorphism do? Only reach for a named pattern if the null fails.
<task>
1. Give the verdict: the pattern — or the simpler construct — in two sentences: what it makes cheap, and what it costs.
2. Name 1-2 plausible alternatives and why they lose HERE, tied to my change pressure and team, not textbook definitions.
3. Refactor my pasted code into the chosen shape: complete code in my language, behaviour preserved — and prove the extension point by actually adding a stub for the next variant I'm likely to need (the fifth provider), showing that adding one is now cheap.
4. Show the seams: a caller before versus after, and where new variants get registered.
5. State the warning signs that this pattern is being outgrown — or was overkill — so future-me can course-correct.
6. Add two tests that pin the pattern's contract in my language's test framework (e.g. "every provider satisfies the interface", "unknown provider fails loudly").
</task>
<output_format>
Verdict — alternatives — refactored code — before/after caller — warning signs — tests.
</output_format>
Rules:
- Preserve observable behaviour exactly; any unavoidable interface change is flagged in bold with its migration step.
- Base the refactor only on pasted code; unseen callers become [CHECK: update call sites in ...].
- If the honest answer is "no pattern — your code is fine", say it and stop at a light cleanup.
Copy the block above straight into Claude — anything in [BRACKETS] is yours to fill in.
Want it tuned to your business? Bring it to the free weekly call and we'll adapt it live.
Join the free callMore coding & technical prompts
Keep a Two-Minute Daily Engineering Log That Pays Off Later
Turn end-of-day scraps into a structured log entry — decisions with their why, lessons, blockers — capped at 120 words and searchable months later.
Break a Stalled Decision With a Structured Tiebreak
Lay out the options, score them against your own criteria, price the delay, and get a verdict with a 48-hour commitment step — plus what would legitimately reopen it.
Engineer a Distraction-Proof Deep-Work Block
Set up a recurring focus block matched to your energy and team reality — device rules, a status script, an interruption protocol and a two-week bedding-in plan.