Implementation reference for the 22 GoF design patterns in idiomatic modern Python (3.10+), with Pythonic forms (dataclasses, singledispatch, match) and class-based fallbacks. Use when refactoring or reviewing Python with pattern-shaped problems like class explosion, type-switching conditionals, or tight coupling.
How this skill is triggered — by the user, by Claude, or both
Slash command
/pproenca-dot-skills-1:implementation-design-patterns-pythonThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
Implementation reference for the 22 Gang of Four design patterns in **idiomatic modern Python (3.10+)**, distilled from refactoring.guru. Each of the **22 pattern files across 3 categories** captures intent, problem, solution, applicability (when to use AND when NOT to), a runnable Python example with output, implementation steps, pros/cons, and relations to sibling patterns.
Implementation reference for the 22 Gang of Four design patterns in idiomatic modern Python (3.10+), distilled from refactoring.guru. Each of the 22 pattern files across 3 categories captures intent, problem, solution, applicability (when to use AND when NOT to), a runnable Python example with output, implementation steps, pros/cons, and relations to sibling patterns.
This is the Pythonic-first companion to the TypeScript design-patterns skill. Most GoF patterns shrink to a language feature in Python — a function, a generator, a dataclass, functools.singledispatch, a match statement. Every entry leads with that idiomatic form and keeps the class-based GoF structure only where identity, stored state, runtime registration, or polymorphic dispatch genuinely earn it.
The patterns are a vocabulary for structural decisions, not a prescription. Reach for one only when its applicability criteria match — every entry includes a When NOT to Use section to guard against over-engineering, which is the more common failure with this catalog in Python.
kind/type/mode/status to pick an algorithm or behavior — a match or if/elif ladder that grows with each variantif isinstance(...), parallel class hierarchies, copy-pasted algorithm skeletons) — make it explicit, or collapse it to a Python idiom| # | Category | Impact | Patterns | When to reach for this group |
|---|---|---|---|---|
| 1 | Creational | HIGH | 5 | Object construction is non-trivial, varies by configuration, or risks tight coupling to concrete classes |
| 2 | Structural | HIGH | 7 | Composing classes/objects into larger structures while keeping parts substitutable |
| 3 | Behavioral | HIGH | 10 | Distributing responsibility and defining how objects collaborate at runtime |
references/{category}-{pattern}.md. Confirm intent, then read Applicability and When NOT to Use before adopting.creational-factory-method — Resolve a concrete class through a registry/dispatch dict. "I want to pick a class by config/string key without an if/elif ladder." — HIGHcreational-abstract-factory — Produce families of related objects that must match. "Switching one flag must swap a whole coordinated set (button + checkbox)." — MEDIUM-HIGHcreational-builder — Construct complex objects step by step — in Python a keyword-only dataclass first. "My constructor has 10+ params, or I need staged assembly." — HIGHcreational-prototype — Clone via copy.deepcopy / dataclasses.replace. "I need another one just like this, with one value changed." — MEDIUMcreational-singleton — One shared instance via a module global or functools.cache. "I need exactly one config/registry/pool, kept testable." — MEDIUMstructural-adapter — Wrap a class so its interface matches what callers expect. "This library's method names don't match mine and I can't edit it." — HIGHstructural-bridge — Split abstraction from implementation via composition + Protocol. "Two orthogonal axes and the subclass count is exploding." — MEDIUMstructural-composite — Treat leaves and trees uniformly via a shared Protocol + recursion. "I have a tree and want one interface for items and groups." — HIGHstructural-decorator — Stack wrappers (or use @decorator) to add behavior at runtime. "I want to layer logging + caching + compression in any order." — HIGHstructural-facade — Expose one function/module over a complex subsystem. "I just want convert(file, fmt), not the codec/bitrate dance." — HIGHstructural-flyweight — Share immutable state via a cached factory + __slots__. "Millions of objects, only a few distinct payloads — out of RAM." — LOW-MEDIUMstructural-proxy — Stand in via __getattr__ / cached_property to control access. "I need lazy loading / auth / caching without touching the real object." — MEDIUM-HIGHbehavioral-chain-of-responsibility — Run a request through an ordered list of handlers. "A pipeline of auth/validate/authorize checks I want to reorder." — MEDIUM-HIGHbehavioral-command — Reify a request as a callable/closure with optional undo. "I need undo/redo, queueing, or one action shared across UI surfaces." — HIGHbehavioral-iterator — Traverse via __iter__/generators without exposing internals. "I want for x in my_structure to just work." — HIGHbehavioral-mediator — Route component interaction through one hub. "My widgets all reference each other and nothing is reusable." — MEDIUMbehavioral-memento — Snapshot/restore state via a frozen dataclass. "I need undo/rollback without exposing private fields." — LOW-MEDIUMbehavioral-observer — Notify subscriber callbacks on change (often a property setter). "Many objects must react when one value changes — events, reactive UI." — CRITICALbehavioral-state — Delegate to polymorphic state objects (or an enum + dispatch). "My class is a state machine with if status == in every method." — MEDIUM-HIGHbehavioral-strategy — Pass an algorithm as a Callable and swap it at runtime. "Multiple algorithms (sort/route/pay) picked without conditionals." — HIGHbehavioral-template-method — Fix a skeleton in an ABC; subclasses override steps. "Several classes share an algorithm with a couple of varying steps." — MEDIUMbehavioral-visitor — Add operations via functools.singledispatch / match. "I need 5 operations across an AST without editing the node classes." — LOW-MEDIUMSeveral patterns share a shape but solve different problems. Read each pattern's Related Patterns section, then apply these distinctions:
Callable swapped at runtime. Template Method uses inheritance — an ABC skeleton fixed at definition time.@classmethod). Abstract Factory returns a family of matching products. Builder assembles one complex product (a keyword-only dataclass, or a fluent builder for staged construction).singledispatch vs. match vs. methods — use functools.singledispatch to add operations over a closed type set without editing the classes; use match when you'd rather keep all cases in one exhaustive function; use plain methods when there's one operation and the type set is small.npx claudepluginhub joshuarweaver/cascade-code-general-misc-1 --plugin pproenca-dot-skills-1Covers 26 Gang of Four design patterns with PHP 8.3+ implementations, UML diagrams, and practical use cases.
Maps code smells like switch-on-type dispatch, subclass explosion, or tangled construction to matching Gang of Four design patterns, then loads the structural recipe from reference files.
Gang of Four patterns (Creational, Structural, Behavioral) and when to apply them.