Skip to main content
skill CX Codex

strategy-pattern — Claude Code skill: what it does, how to install

Implements the Strategy pattern in Symfony using tagged services. Helps clean up branching logic when algorithms or providers vary at runtime.

MIT ★ 234 updated 2026-10-05

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add dev-toolings/superpowers-symfony --skill strategy-pattern -a claude-code
Open on GitHub

What strategy-pattern does

This skill guides the implementation of the Strategy pattern in Symfony projects without letting match or switch blocks grow out of hand. It defines a strategy interface with a supports() check or a unique key, registers implementations via #[AutoconfigureTag], and sets up injection with #[AutowireIterator] or #[AutowireLocator].

The generated structure includes a selector that fails explicitly if no strategy matches, fallback handling, priority sorting, and unit tests using test doubles. For fixed two-branch scenarios that will not expand, the instructions advise keeping a plain match statement instead of introducing extra classes.

What it helps with

  • replace growing switch or match blocks on type strings
  • iterate through algorithm implementations via #[AutowireIterator]
  • resolve keyed services using Symfony #[AutowireLocator]
  • add payment gateways or export formats without touching selector code

Example prompts for the agent

  • Refactor our payment provider selection into Symfony tagged strategies
  • Create an export strategy selector using AutowireIterator with priority ordering
  • Write unit tests for the strategy selector covering the no-match failure case

How to install strategy-pattern

1Skills CLI (Vercel)

npx skills add dev-toolings/superpowers-symfony --skill strategy-pattern -a claude-code

2Manually: put the files in place

~/.claude/skills/strategy-pattern/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/strategy-pattern/

Step by step, with commands for each platform: How to install skills in Claude Code: five ways

Questions about strategy-pattern

How to install strategy-pattern in Claude Code?

Run npx skills add dev-toolings/superpowers-symfony --skill strategy-pattern -a claude-code in your terminal.

What does strategy-pattern do?

It guides Claude Code to build stateless Symfony strategy classes, configure tagged service locators or iterators, and test selector fallbacks.

When does the skill advise skipping the Strategy pattern?

When there are only two static cases that will not grow, a native match expression is preferred over the full pattern.

Source text

SKILL.md · MIT
---
name: strategy-pattern
description: Implement the Strategy pattern with Symfony's tagged services for runtime algorithm selection and extensibility
capabilities: [read, search]
tags: [architecture]
# projected by `bun run build` — do not edit by hand
allowed-tools:
  - Read
  - Glob
  - Grep
---

# Strategy Pattern (Symfony)

## Use when
- One operation has several interchangeable algorithms chosen at runtime, such as payment providers or export formats.
- A `switch` or `match` on a type string keeps growing.
- New variants must be added without editing the code that selects them.

## Default workflow
1. Define the strategy interface, with a `supports()` method or a key per strategy.
2. Tag every implementation through `#[AutoconfigureTag]` on the interface or on each class.
3. Inject them with `#[AutowireIterator]` to try each in order, or `#[AutowireLocator]` to fetch one by key.
4. Set priorities where evaluation order matters, and register a fallback strategy.
5. 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 `match` is 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`

© dev-toolings · MIT · dev-toolings/superpowers-symfony

Similar skills

All skills for Backend and APIs →

From the same set51

The whole set →
quality-checks Runs PHP-CS-Fixer for code style, PHPStan for static analysis, and type checking. Use before committing or when CI quality checks fail. CX Codex +1 ★ 234repo stars writing-plans writing-plans generates structured implementation plans for Symfony features with clear steps, acceptance criteria, and risk mitigations. CX Codex +1 ★ 234repo stars value-objects-and-dtos This skill guides Symfony work with immutable Value Objects and DTOs, covering constructor validation, value equality, and data crossing application boundaries. CX Codex +1 ★ 234repo stars effective-context effective-context is a Claude Code skill that teaches an agent to gather context for Symfony development: versions, error-path files, stack traces, and project constraints. CX Codex +1 ★ 234repo stars executing-plans The executing-plans skill guides Claude Code through an approved implementation plan, with test-first steps and a separate commit for each one. Use it for multi-step work or to resume after an interruption. CX Codex +1 ★ 234repo stars twig-components twig-components turns repeated Twig markup into Symfony UX components with props, slots and CVA variants. Handy once the same template chunk starts getting copied around. CX Codex +1 ★ 234repo stars cqrs-and-handlers cqrs-and-handlers implements CQRS in Symfony projects using separate Messenger buses for commands and queries. CX Codex +1 ★ 234repo stars daily-workflow The daily-workflow skill lays out a routine for Symfony work, from getting a project running to checking changes before a commit. Use it for migrations, debugging, and recurring maintenance. CX Codex +1 ★ 234repo stars

Project sponsors

Companies that keep this analytics open