design-patterns

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).

Safety Notice

This listing is imported from skills.sh public index metadata. Review upstream SKILL.md and repository scripts before running.

Copy this and send it to your AI assistant to learn

Install skill "design-patterns" with this command: npx skills add fellipeutaka/leon/fellipeutaka-leon-design-patterns

Design Patterns

Proven architectural patterns for building maintainable, extensible, and testable TypeScript codebases. All 22 Gang of Four patterns with practical implementations.

When to Apply

Reference these patterns when:

  • Solving recurring architectural problems
  • Refactoring tightly coupled code
  • Building plugin/extension systems
  • Making code more testable via dependency injection
  • Reviewing PRs with architectural concerns
  • Choosing between inheritance and composition

Pattern Categories

Creational Patterns

Create objects flexibly, hiding creation logic from consumers.

PatternIntent
Factory MethodDelegate object creation to subclasses
Abstract FactoryCreate families of related objects without concrete types
BuilderConstruct complex objects step-by-step
PrototypeClone existing objects instead of building from scratch
SingletonEnsure exactly one instance with global access

See references/CREATIONAL.md for implementations.

Structural Patterns

Compose classes and objects into larger, flexible structures.

PatternIntent
AdapterMake incompatible interfaces work together
BridgeSeparate abstraction from implementation
CompositeTreat individual objects and compositions uniformly
DecoratorAttach responsibilities dynamically without subclassing
FacadeSimplify complex subsystem with a unified interface
FlyweightShare common state to reduce memory across many objects
ProxyControl access to an object through a substitute

See references/STRUCTURAL.md for implementations.

Behavioral Patterns

Manage algorithms, responsibilities, and communication between objects.

PatternIntent
Chain of ResponsibilityPass requests along a handler chain
CommandEncapsulate requests as objects for queuing/undo
IteratorTraverse collections without exposing internals
MediatorCentralize complex communication between objects
MementoCapture and restore object state
ObserverNotify dependents automatically on state changes
StateAlter behavior when internal state changes
StrategySwap algorithms at runtime
Template MethodDefine algorithm skeleton, let subclasses override steps
VisitorAdd operations to objects without modifying them

See references/BEHAVIORAL.md for implementations.

Pattern Selection Guide

ProblemPattern(s)
Need to decouple object creationFactory Method, Abstract Factory
Complex object with many optional fieldsBuilder
Expensive object creation, need copiesPrototype
Global shared resource (config, pool)Singleton
Incompatible third-party interfaceAdapter
Multiple dimensions of variationBridge
Tree structures (files, UI, org charts)Composite
Add features without subclassingDecorator
Simplify complex API surfaceFacade
Thousands of similar objects, memory heavyFlyweight
Lazy loading, access control, cachingProxy
Flexible request processing pipelineChain of Responsibility
Undo/redo, task queues, macrosCommand
Custom collection traversalIterator
Many-to-many object communicationMediator
Snapshots, save/restore stateMemento
Event systems, reactive updatesObserver
Object behavior depends on its stateState
Swappable algorithms (sort, compress, etc)Strategy
Algorithm with fixed steps, variable partsTemplate Method
Operations across heterogeneous objectsVisitor

Best Practices

DO

  • Choose patterns that solve actual problems you're facing now
  • Prefer composition over inheritance
  • Use dependency injection to decouple components
  • Keep pattern implementations simple — avoid gold-plating
  • Document why a pattern was chosen (not just which one)
  • Consider testability when choosing patterns
  • Combine patterns when appropriate (e.g., Strategy + Factory)

DON'T

  • Apply patterns preemptively for hypothetical future needs
  • Force a pattern where a simple function/object suffices
  • Create unnecessary abstraction layers
  • Use Singleton as a disguised global variable
  • Choose inheritance when composition works better
  • Ignore team familiarity — a simpler pattern everyone knows beats a "better" one nobody understands

SOLID Quick Reference

PrincipleSummaryRelated Patterns
Single ResponsibilityOne class, one reason to changeStrategy, Command, Observer
Open/ClosedOpen for extension, closed for modificationDecorator, Strategy, Template Method
Liskov SubstitutionSubtypes must be substitutable for base typesFactory Method, Abstract Factory
Interface SegregationPrefer small, focused interfacesAdapter, Facade
Dependency InversionDepend on abstractions, not concretionsAll patterns using interfaces/abstract

Source Transparency

This detail page is rendered from real SKILL.md content. Trust labels are metadata-based hints, not a safety guarantee.

Related Skills

Related by shared tags or category signals.

General

docker

No summary provided by upstream source.

Repository SourceNeeds Review
General

commit-work

No summary provided by upstream source.

Repository SourceNeeds Review
General

motion

No summary provided by upstream source.

Repository SourceNeeds Review