Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

implementation-design-patterns-python

БесплатноБез исполняемых скриптовНе проверен

Implementation guide for the 22 Gang of Four design patterns in idiomatic modern Python (3.10+), distilled from refactoring.guru. Use when writing…

pproencaот pproenca★ 231 звезда на GitHub

Об этом скилле

Python Design Patterns Best Practices (Refactoring Guru)

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.

When to Apply

  • A constructor has grown to 10+ parameters (telescoping-constructor smell) or subclasses exist only to bake in parameter combinations
  • A method branches on kind/type/mode/status to pick an algorithm or behavior — a match or if/elif ladder that grows with each variant
  • Integrating an incompatible third-party API, library, or legacy class whose method names don't match your code
  • Modeling a tree-shaped domain (file systems, ASTs, UI trees, org charts) where leaves and branches must be treated uniformly
  • Adding cross-cutting behavior at runtime — logging, caching, access control, compression — without subclassing
  • Selecting an algorithm or behavior variant at runtime from config, user input, or environment
  • Implementing undo/redo, history snapshots, transactional rollback, or queueing/scheduling of operations
  • Coordinating many objects whose direct mutual references have become tangled — a hub that brokers communication
  • Notifying many subscribers when something changes — event systems, reactive data flows
  • Reviewing code that smells like a pattern is implicit (a giant if isinstance(...), parallel class hierarchies, copy-pasted algorithm skeletons) — make it explicit, or collapse it to a Python idiom

Rule Categories

# 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

How to Use

  1. Recognize the shape. Read the Quick Reference below and identify which pattern's intent matches your problem. Most pattern-shaped problems sound like one of the listed phrases.
  2. Read the pattern reference. Open references/{category}-{pattern}.md. Confirm intent, then read Applicability and When NOT to Use before adopting.
  3. Lead with the idiom. Each "Correct" example shows the Pythonic form first. Adopt it unless you need the class-based structure shown in the Alternative block.
  4. Adapt to your domain. The examples use small realistic domains (transports, route planners, document trees). Rename to your terms before merging.
  5. Check the relations. Each entry ends with Related Patterns — siblings worth considering for the same problem.

Quick Reference

1. Creational Patterns (object instantiation)

  • 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." — HIGH
  • creational-abstract-factory — Produce families of related objects that must match. "Switching one flag must swap a whole coordinated set (button + checkbox)." — MEDIUM-HIGH
  • creational-builder — Construct complex objects step by step — in Python a keyword-only dataclass first. "My constructor has 10+ params, or I need staged assembly." — HIGH
  • creational-prototype — Clone via copy.deepcopy / dataclasses.replace. "I need another one just like this, with one value changed." — MEDIUM
  • creational-singleton — One shared instance via a module global or functools.cache. "I need exactly one config/registry/pool, kept testable." — MEDIUM

2. Structural Patterns (composition)

Полный SKILL.md на GitHub

Установить implementation-design-patterns-python в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

Вложенные файлы

AGENTS.mdgotchas.mdmetadata.jsonreferences/_sections.mdreferences/behavioral-chain-of-responsibility.mdreferences/behavioral-command.mdreferences/behavioral-iterator.mdreferences/behavioral-mediator.mdreferences/behavioral-memento.mdreferences/behavioral-observer.mdreferences/behavioral-state.mdreferences/behavioral-strategy.mdreferences/behavioral-template-method.mdreferences/behavioral-visitor.mdreferences/creational-abstract-factory.mdreferences/creational-builder.mdreferences/creational-factory-method.mdreferences/creational-prototype.mdreferences/creational-singleton.mdreferences/structural-adapter.mdreferences/structural-bridge.mdreferences/structural-composite.mdreferences/structural-decorator.mdreferences/structural-facade.mdreferences/structural-flyweight.mdreferences/structural-proxy.md

FAQ

Что делает скилл implementation-design-patterns-python?

Implementation guide for the 22 Gang of Four design patterns in idiomatic modern Python (3.10+), distilled from refactoring.guru. Use when writing, refactoring, or reviewing Python with a pattern-shaped problem — class-explosion from inheritance, conditionals switching on type, tight coupling to concrete classes, tree-shaped models, runtime algorithm selection, undo/redo, state-dependent behavior, or hiding subsystem complexity. Each entry leads with the Pythonic form (functions, dataclasses, Protocol, singledispatch, match, generators, copy/replace) and falls back to the class-based GoF structure only when identity, state, or dispatch require it. Includes intent, applicability (when to use AND when NOT to), a runnable example, steps, pros/cons, and relations. Trigger even when no pattern is named — cues like "too many constructor params," "giant if/elif," "swap behavior at runtime," "need undo," or "walk a tree" are pattern-shaped. Covers all 5 Creational, 7 Structural, and 10 Behavioral GoF patterns.

Как установить скилл implementation-design-patterns-python?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл implementation-design-patterns-python запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить implementation-design-patterns-python с