strategy-pattern-implementor
Installation
SKILL.md
Strategy Pattern Implementor
When to Use
You have a class that selects between algorithm variants and need to refactor it so algorithms can vary independently from the clients that use them. This skill applies when:
- A class contains
switchstatements orif/elsechains that select between behavioral variants — the primary code smell - Multiple related classes differ only in their behavior (same structure, different computation)
- You need different space-time trade-offs for the same operation (fast-and-approximate vs. slow-and-precise)
- An algorithm uses data clients should not know about (complex internal data structures that would leak through the interface)
- You need to swap the algorithm at runtime without changing the client
Before starting, confirm:
- Is this a client-selected algorithm switch (Strategy) rather than an object self-transitioning based on internal state (State)? If unsure, use
behavioral-pattern-selectorfirst. - Does the variation belong in the class itself, or is it better expressed via a superclass skeleton with subclass steps (Template Method via inheritance)? Strategy uses composition — the algorithm is a separate object, not a subclass.