Loading...
Loading...
Apply Gang of Four design patterns to solve architectural problems in TypeScript. Use when refactoring code architecture, implementing extensible systems, decoupling components, or following SOLID principles. Covers all 22 GoF patterns: Creational (Factory Method, Abstract Factory, Builder, Prototype, Singleton), Structural (Adapter, Bridge, Composite, Decorator, Facade, Flyweight, Proxy), and Behavioral (Chain of Responsibility, Command, Iterator, Mediator, Memento, Observer, State, Strategy, Template Method, Visitor).
npx skill4agent add marcioaltoe/skills design-patterns| Pattern | Intent |
|---|---|
| Factory Method | Delegate object creation to subclasses |
| Abstract Factory | Create families of related objects without concrete types |
| Builder | Construct complex objects step-by-step |
| Prototype | Clone existing objects instead of building from scratch |
| Singleton | Ensure exactly one instance with global access |
references/CREATIONAL.md| Pattern | Intent |
|---|---|
| Adapter | Make incompatible interfaces work together |
| Bridge | Separate abstraction from implementation |
| Composite | Treat individual objects and compositions uniformly |
| Decorator | Attach responsibilities dynamically without subclassing |
| Facade | Simplify complex subsystem with a unified interface |
| Flyweight | Share common state to reduce memory across many objects |
| Proxy | Control access to an object through a substitute |
references/STRUCTURAL.md| Pattern | Intent |
|---|---|
| Chain of Responsibility | Pass requests along a handler chain |
| Command | Encapsulate requests as objects for queuing/undo |
| Iterator | Traverse collections without exposing internals |
| Mediator | Centralize complex communication between objects |
| Memento | Capture and restore object state |
| Observer | Notify dependents automatically on state changes |
| State | Alter behavior when internal state changes |
| Strategy | Swap algorithms at runtime |
| Template Method | Define algorithm skeleton, let subclasses override steps |
| Visitor | Add operations to objects without modifying them |
references/BEHAVIORAL.md| Problem | Pattern(s) |
|---|---|
| Need to decouple object creation | Factory Method, Abstract Factory |
| Complex object with many optional fields | Builder |
| Expensive object creation, need copies | Prototype |
| Global shared resource (config, pool) | Singleton |
| Incompatible third-party interface | Adapter |
| Multiple dimensions of variation | Bridge |
| Tree structures (files, UI, org charts) | Composite |
| Add features without subclassing | Decorator |
| Simplify complex API surface | Facade |
| Thousands of similar objects, memory heavy | Flyweight |
| Lazy loading, access control, caching | Proxy |
| Flexible request processing pipeline | Chain of Responsibility |
| Undo/redo, task queues, macros | Command |
| Custom collection traversal | Iterator |
| Many-to-many object communication | Mediator |
| Snapshots, save/restore state | Memento |
| Event systems, reactive updates | Observer |
| Object behavior depends on its state | State |
| Swappable algorithms (sort, compress, etc) | Strategy |
| Algorithm with fixed steps, variable parts | Template Method |
| Operations across heterogeneous objects | Visitor |
| Principle | Summary | Related Patterns |
|---|---|---|
| Single Responsibility | One class, one reason to change | Strategy, Command, Observer |
| Open/Closed | Open for extension, closed for modification | Decorator, Strategy, Template Method |
| Liskov Substitution | Subtypes must be substitutable for base types | Factory Method, Abstract Factory |
| Interface Segregation | Prefer small, focused interfaces | Adapter, Facade |
| Dependency Inversion | Depend on abstractions, not concretions | All patterns using interfaces/abstract |