gof-factory
Installation
SKILL.md
One-line summary
Centralize the choice of which concrete class to instantiate, hiding it from clients — in three flavors of increasing scope: Simple Factory (one method picks a type), Factory Method (subclasses pick a type), Abstract Factory (a family of related types).
When to use this skill
- Client code is full of
new ConcreteX()decisions and the choice depends on input data, configuration, or environment. - Two parallel hierarchies need to pick matched implementations together (e.g., a
NYStylePizzaStoreshould produceNYStyleDough,NYStyleSauce— that's Abstract Factory). - Subclasses should decide which concrete type to instantiate while sharing the surrounding workflow — Factory Method.
- Construction itself has invariants that the constructor alone can't enforce.
When NOT to use this skill
- Only one concrete type exists; just call its constructor.
- A simple top-level function (
fun parsePayment(json): Payment) is enough — naming a class*Factoryfor a single function adds nothing. - Construction is genuinely trivial and adding indirection just because "factories are best practice" is ceremony.