About strategy-pattern
A strategy-pattern skill for Symfony developers that guides the separation of interchangeable algorithms and their runtime selection. It covers service tagging, injection, priorities, fallback behavior, and tests.
Key features
- 01Define a strategy interface and implementations
- 02Inject with AutowireIterator or AutowireLocator
- 03Configure priorities and fallback behavior
- 04Test strategies and the selector
Use cases
- 01Select payment providers at runtime
- 02Switch between export formats
- 03Replace a growing type-based switch
Install
Copy the command and run it in a terminal.
$
npx skills add https:/ / github.com/ dev-toolings/ superpowers-symfony --skill strategy-patternAfter installing, type/strategy-patternin Claude Code to confirm it loaded.
Bundled filesreference.md
Details
From the project READMEStrategy Pattern (Symfony)
Use when
- One operation has several interchangeable algorithms chosen at runtime, such as payment providers or export formats.
- A
switchormatchon a type string keeps growing. - New variants must be added without editing the code that selects them.
Default workflow
- Define the strategy interface, with a
supports()method or a key per strategy. - Tag every implementation through
#[AutoconfigureTag]on the interface or on each class. - Inject them with
#[AutowireIterator]to try each in order, or#[AutowireLocator]to fetch one by key. - Set priorities where evaluation order matters, and register a fallback strategy.
- Test each strategy alone, and the selector with fakes.
Guardrails
- The selector fails explicitly when no strategy supports the input.
- Keep strategies stateless and independent of each other.
- Two cases that will not grow do not need the pattern: a
matchis enough.
Progressive disclosure
- Use this file for execution posture and risk controls.
- Open references when deep implementation details are needed.
Output contract
- The interface and its tagged implementations.
- The selector, with its order and its fallback.
- Tests per strategy and for the no-match case.
References
reference.md
Comments
Markdown supported