gof-strategy
Installation
SKILL.md
One-line summary
Encapsulate each member of a family of algorithms behind a common interface and let the client compose the one it needs at runtime — instead of hardcoding the algorithm or branching on a type flag.
When to use this skill
- A class has a branching
switch/ifon a "type" field that selects between alternate algorithms (sort orders, pricing rules, validation strategies). - Subclassing has been used to vary one piece of behavior, leading to a combinatorial explosion of classes.
- The set of algorithms is expected to grow.
- Two classes share most behavior but differ in a single dimension (e.g.,
MallardDuckandRubberDuckdiffer only in how they quack and fly).
When NOT to use this skill
- Only one algorithm exists and no second one is in sight — adding the indirection is YAGNI.
- The varying behavior involves a sequence of steps with mostly identical structure — that's
gof-template-method. - The variation is what gets composed not how it computes — that's often
gof-decorator.