This skill should be used when the user asks about "abstract factory pattern", "factory of factories", "family of objects", "when to use abstract factory", "implement abstract factory", or mentions needing to create families of related objects.
How this skill is triggered — by the user, by Claude, or both
Slash command
/design-pattern-skills:abstract-factoryThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
The Abstract Factory pattern provides an interface for creating families of related or dependent objects without specifying their concrete classes. It's essentially a "factory of factories" that ensures created objects work together.
The Abstract Factory pattern provides an interface for creating families of related or dependent objects without specifying their concrete classes. It's essentially a "factory of factories" that ensures created objects work together.
// Abstract products
interface Button { render(): string; }
interface Input { render(): string; }
// Concrete products - Light theme
class LightButton implements Button {
render() { return 'Light button'; }
}
class LightInput implements Input {
render() { return 'Light input'; }
}
// Concrete products - Dark theme
class DarkButton implements Button {
render() { return 'Dark button'; }
}
class DarkInput implements Input {
render() { return 'Dark input'; }
}
// Abstract factory
interface GUIFactory {
createButton(): Button;
createInput(): Input;
}
// Concrete factories
class LightThemeFactory implements GUIFactory {
createButton(): Button { return new LightButton(); }
createInput(): Input { return new LightInput(); }
}
class DarkThemeFactory implements GUIFactory {
createButton(): Button { return new DarkButton(); }
createInput(): Input { return new DarkInput(); }
}
// Usage
function buildUI(factory: GUIFactory) {
const button = factory.createButton();
const input = factory.createInput();
console.log(button.render(), input.render());
}
See examples/ directory for runnable TypeScript implementations:
examples/abstract-factory.ts - Basic implementation with furniture factoryexamples/abstract-factory-advanced.ts - Real-world example with database providersnpx claudepluginhub keohanoi/design-pattern-skills --plugin design-pattern-skillsCentralizes object creation for families of related objects, enabling easy swapping of product families without client code changes. Based on the GoF pattern.
Implements the Abstract Factory creational pattern in JavaScript to create families of related objects (e.g., UI themes) without specifying concrete classes. Useful when product families must be swapped at runtime.
Gang of Four patterns (Creational, Structural, Behavioral) and when to apply them.