agentleFS
robconeryrobconery/kolea/.claude/skills/gof-patterns/SKILL.md

gof-patterns

Skill7 starsChanged 3 months agoMITView on GitHub

Gang of Four design patterns reference for TypeScript projects. Use when choosing or implementing a design pattern, refactoring toward a known pattern, reviewing code for pattern misuse, or answering "which pattern fits here" questions. Covers all 23 creational, structural, and behavioral patterns with idiomatic TypeScript examples and guidance on when (and when not) to use each.

1 other project uses a version of this.

Adopted by

Most recently taken up by

  • Other versions1 project uses a version of this.

    Word for word · 0

    None found.

    Edited · 0

    None found.

    Wrote their own version · 1

    1. grndlvl/software-patterns★ 17same name

    How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.

  • In this repository12 other files it gives its agents.

The file

We split this skill into the rules it gives an agent

2 rules. About 0 are common, 2 are distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈2

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Prefer the simplest construct that solves the problem.

    line 31
  2. Distinctive:

    Use the class form only when you need lazy init or to swap the instance in tests.

    line 75

≈ “Common” is an estimate: at least 1 in 5 of the 364,980 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Gang of Four Patterns in TypeScript

The 23 classic design patterns from Design Patterns: Elements of Reusable Object-Oriented Software (Gamma, Helm, Johnson, Vlissides), adapted to idiomatic TypeScript.

🎯 Why: Design for Change

The goal of writing software is to be able to change it safely. Every GoF pattern is a named seam that isolates one axis of change: Strategy hides algorithm choice, Adapter hides a vendor swap, Observer hides who's listening, Factory hides what's instantiated. Reach for a pattern when you have a demonstrated axis of change to absorb. A pattern installed speculatively adds coupling without buying any change-safety.

How to use this skill

  1. Identify the kind of problem from the decision guide below.
  2. Open the matching reference file for the full TypeScript example and the "when to use / when not to" notes.
  3. Prefer the simplest construct that solves the problem. In TypeScript, a union type, a closure, or a plain function often beats a class-heavy pattern. Reach for a GoF pattern when the indirection earns its keep.

Reference files

  • references/creational.md — object creation: Factory Method, Abstract Factory, Builder, Prototype, Singleton.
  • references/structural.md — object composition: Adapter, Bridge, Composite, Decorator, Facade, Flyweight, Proxy.
  • references/behavioral.md — object interaction & responsibility: Chain of Responsibility, Command, Interpreter, Iterator, Mediator, Memento, Observer, State, Strategy, Template Method, Visitor.

Decision guide — symptom → pattern

You are trying to…ConsiderCategory
Create objects without naming the concrete classFactory Method, Abstract FactoryCreational
Build a complex object step by stepBuilderCreational
Copy an existing objectPrototypeCreational
Guarantee exactly one instanceSingleton (often a module instead)Creational
Make an incompatible interface usableAdapterStructural
Vary abstraction and implementation independentlyBridgeStructural
Treat individual objects and groups uniformlyCompositeStructural
Add behavior to objects without subclassingDecoratorStructural
Hide a complex subsystem behind one interfaceFacadeStructural
Share many fine-grained objects cheaplyFlyweightStructural
Control access to an object (lazy, remote, guarded)ProxyStructural
Pass a request along a series of handlersChain of ResponsibilityBehavioral
Encapsulate a request as an object (undo, queue)CommandBehavioral
Evaluate sentences in a small languageInterpreterBehavioral
Traverse a collection without exposing its structureIteratorBehavioral
Reduce many-to-many object couplingMediatorBehavioral
Capture and restore object stateMementoBehavioral
Notify dependents of state changesObserverBehavioral
Change behavior when internal state changesStateBehavioral
Swap one of several algorithms at runtimeStrategyBehavioral
Fix an algorithm skeleton, vary stepsTemplate MethodBehavioral
Add operations to a class hierarchy without editing itVisitorBehavioral

TypeScript-specific guidance

  • Singleton: an ES module with exported bindings is already a singleton. Use the class form only when you need lazy init or to swap the instance in tests.
  • Strategy / Command / State: a function or a discriminated union is often lighter than a class hierarchy. Use classes when strategies carry state.
  • Prototype: structuredClone() covers most deep-copy needs; implement clone() only for objects with methods or non-cloneable fields.
  • Observer: EventTarget, EventEmitter, or an RxJS Subject are battle-tested implementations — hand-roll only for learning or tight control.
  • Decorator: the TC39/experimental @decorator syntax is a language feature, not the GoF pattern. The GoF Decorator is object composition; keep them mentally separate.
  • Favor interface for pattern contracts and discriminated unions for closed sets of variants; lean on readonly and as const for immutability in Memento/Prototype.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.