Claude-skill-registry gof-patterns

Gang of Four design patterns reference. Use this skill when implementing, discussing, or choosing object-oriented design patterns. Auto-activates for architecture decisions, refactoring, and decoupling concerns. Comprehensive coverage of all 23 GoF patterns with pseudocode examples.

install
source · Clone the upstream repo
git clone https://github.com/majiayu000/claude-skill-registry
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/majiayu000/claude-skill-registry "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/data/gof-patterns" ~/.claude/skills/majiayu000-claude-skill-registry-gof-patterns && rm -rf "$T"
manifest: skills/data/gof-patterns/SKILL.md
source content

GoF Design Patterns Reference

A comprehensive reference for the Gang of Four design patterns. This skill provides language-agnostic guidance with pseudocode examples that can be translated to any programming language.

When This Skill Activates

This skill automatically activates when you:

  • Ask about or need to implement a design pattern
  • Need to choose between patterns for a design problem
  • Are refactoring code and considering structural improvements
  • Discuss architecture, decoupling, or extensibility
  • Mention specific patterns: factory, singleton, observer, decorator, etc.

Quick Pattern Reference

Creational Patterns (Object Creation)

PatternIntentUse When
Abstract FactoryCreate families of related objectsNeed platform/theme independence
BuilderConstruct complex objects step-by-stepObject has many optional parts
Factory MethodLet subclasses decide which class to instantiateDon't know concrete types ahead of time
PrototypeClone existing objectsObject creation is expensive
SingletonEnsure single instanceNeed exactly one shared instance

Structural Patterns (Composition)

PatternIntentUse When
AdapterConvert interface to expected interfaceIntegrating incompatible interfaces
BridgeSeparate abstraction from implementationNeed to vary both independently
CompositeTreat individual and groups uniformlyHave tree structures
DecoratorAdd responsibilities dynamicallyNeed flexible extension
FacadeSimplified interface to subsystemComplex subsystem needs simple API
FlyweightShare common state efficientlyMany similar objects needed
ProxyControl access to objectNeed lazy loading, access control, logging

Behavioral Patterns (Communication)

PatternIntentUse When
Chain of ResponsibilityPass request along handler chainMultiple handlers, unknown which handles
CommandEncapsulate request as objectNeed undo, queue, or log operations
InterpreterDefine grammar and interpret sentencesHave a simple language to parse
IteratorSequential access without exposing internalsNeed to traverse collections
MediatorCentralize complex communicationsMany objects communicate in complex ways
MementoCapture and restore object stateNeed undo/snapshot functionality
ObserverNotify dependents of state changesOne-to-many dependency
StateAlter behavior when state changesObject behavior depends on state
StrategyEncapsulate interchangeable algorithmsNeed to swap algorithms at runtime
Template MethodDefine skeleton, let subclasses fill inAlgorithm structure fixed, steps vary
VisitorAdd operations without changing classesNeed to add many operations to stable structure

Decision Guide

See Pattern Selection Guide for help choosing the right pattern.

How to Use This Reference

  1. Choosing a pattern: Start with the decision guide or tables above
  2. Learning a pattern: Read the full documentation with examples
  3. Quick reminder: Use the tables above for at-a-glance reference
  4. Implementation: Follow the pseudocode, adapt to your language

Language Translation Notes

The pseudocode in this reference uses these conventions:

  • class
    for type definitions
  • function
    for methods/functions
  • ->
    for method calls on objects
  • //
    for comments
  • Type hints shown as
    name: Type

Translate to your language:

  • PHP:
    class
    ,
    function
    ,
    ->
    ,
    //
    , type hints in docblocks or PHP 8+
  • JavaScript/TypeScript:
    class
    ,
    function
    /arrow,
    .
    ,
    //
    , TS types
  • Python:
    class
    ,
    def
    ,
    .
    ,
    #
    , type hints
  • Java/C#: Direct mapping with
    new
    , generics

Based on concepts from "Design Patterns: Elements of Reusable Object-Oriented Software" by Gamma, Helm, Johnson, and Vlissides (Gang of Four), 1994.