yonatankarp/software-design-skills

gof-identify

Use when the user has a design problem and is asking which GoF pattern (if any) fits — phrases like "which design pattern should I use", "is this an Observer or a Mediator", "what pattern handles this", "I'm not sure if it's Strategy or State", "help me pic…

查看源码

使用方法

  1. 复制安装命令,在自己的智能体环境安装前先检查源码包。
  2. 从原始文档核对所需工具、凭据和支持的宿主。
  3. 说明输入材料与期望交付物,并对照来源检查输出。
npx skills add https://github.com/yonatankarp/software-design-skills --skill gof-identify

开始前需了解

  • 安装不包含模型订阅、API 额度或访问文件的权限。
  • 仓库星数和安装量反映活跃情况,不等于独立质量或安全测试。
仓库原始内容

按源仓库内容呈现,保留标题、案例、代码、表格、链接以及原文引用的演示图片。

One-line summary

Diagnose which Gang-of-Four pattern fits a stated design problem — or rule patterns out and point at a simpler solution.

When to use this skill

  • The user has described a design problem and wants to know which pattern applies.
  • The user is confused between two patterns that look similar (Strategy vs State, Decorator vs Proxy, Adapter vs Facade).
  • The user is about to introduce a pattern but isn't sure it's the right one.

When NOT to use this skill

  • The user already knows the pattern they want — go directly to that pattern skill (e.g., gof-observer).
  • The user wants to refactor existing code toward a known pattern → route to gof-refactor-to-pattern.
  • The user wants to audit code for misused patterns → route to gof-review.

Core content

Walk the problem with these diagnostic questions, in this order:

1. What is varying?

  • The algorithm itself, client-chosen at runtime: gof-strategy.
  • The algorithm itself, changing with object lifecycle: gof-state.
  • Steps within an algorithm, base class fixes the skeleton: gof-template-method.
  • Behavior added/removed at runtime, in any combination: gof-decorator.

2. Is it a creation problem?

  • Choosing which concrete class to instantiate: gof-factory.
  • Assembling an object via many (often optional) parameters or staged steps: gof-builder.
  • Creating a new instance by copying an existing one with a few fields changed: gof-prototype.
  • Making sure there's only one instance: gof-singleton — but check first whether language features (Kotlin object, DI scoping) make the pattern unnecessary.

3. Is it a "wrap one object in another" problem?

  • Add behavior: gof-decorator.
  • Change interface: gof-adapter.
  • Control access (lazy/remote/permission): gof-proxy.
  • Simplify a subsystem behind one entry point: gof-facade.

4. Is it a structural problem?

  • Part-whole hierarchy, treat leaves and branches uniformly: gof-composite.
  • Traverse a collection without exposing its internals: gof-iterator.
  • Two orthogonal dimensions of variation (NxM subclass explosion otherwise): gof-bridge.

5. Is it a behavioral / communication problem?

  • One subject, many dependents that need updates: gof-observer.
  • Encapsulate a request as an object (queue, log, undo): gof-command.
  • Add new operations over a stable hierarchy without modifying its element classes: gof-visitor — but in Kotlin, prefer sealed + exhaustive when.

6. None of the above? The problem may not need a GoF pattern at all. Common cases:

  • A plain function would solve it.
  • The language has a feature that supersedes the pattern (Kotlin object for Singleton, by delegation for Decorator, function types for Strategy).
  • The problem is in the domain, not in the design — route to ddd-design or similar.

Decision heuristics

  • Don't reach for a pattern when "a function" or "a language feature" would do.
  • Strategy and State have identical structure — distinguish by intent (client-chosen vs lifecycle-driven).
  • Decorator and Proxy have identical structure — distinguish by intent (add behavior vs control access).
  • Adapter and Facade differ in scope — single class to a different interface vs subsystem to a simpler one.

Anti-patterns

  • "Let's introduce a pattern" before identifying the problem — premature abstraction.
  • Naming things after patterns (OrderManager, CustomerStrategy) that don't actually use the pattern — pattern theatre.
  • Choosing the pattern based on what the team is excited about rather than what the problem calls for.

See also

  • All thirteen pattern skills (gof-strategy, gof-observer, …).
  • gof-review — when the question is "is this code using the pattern correctly?" rather than "which pattern fits?".
  • gof-refactor-to-pattern — when the destination is known and the question is "how do I get there?".

References

  • Head First Design Patterns (2nd ed), Ch. 13 ("Patterns in the Real World") — discusses how to recognize which pattern applies in practice.
  • Design Patterns (Gamma, Helm, Johnson, Vlissides, 1994) — the original pattern catalog and its "intent / motivation / applicability" framing.

按任务相关推荐

来自同一仓库

更多 Skills

全部 Skills
yonatankarp
社区

arch-adr

Use when recording an architectural decision so future maintainers know why — phrases like "ADR", "architecture decision record", "why did we pick X", "lightweight architecture documentation", "decision log", "should this be an ADR", "tribal knowledge", "we chose this two years ago and now nobody remembers why". Defines the ADR as a short, structured document capturing what was decided, why, alternatives considered, and consequences — written at the time of the decision and kept in the repo.

安装量
2
GitHub Stars
1
最近更新
5月19日
yonatankarp
社区

arch-fitness-functions

Use when enforcing architectural characteristics through automation — phrases like "architecture fitness function", "evolutionary architecture", "architecture tests", "ArchUnit", "dependency rules in CI", "automated architecture checks", "guardrails", "drift detection". Defines fitness functions as automated checks that verify architectural characteristics on every change, catching drift before it accumulates.

安装量
2
GitHub Stars
1
最近更新
5月19日
yonatankarp
社区

arch-microservices

Use when designing or reviewing a microservices architecture — phrases like "microservices", "should we split this service", "service boundaries", "bounded context per service", "API gateway", "backend for frontend", "BFF", "service mesh", "microservices vs monolith", "database per service", "data ownership". Defines microservices as independently deployable services aligned with business capabilities — and the discipline of resisting the style until the monolith proves inadequate.

安装量
2
GitHub Stars
1
最近更新
5月19日
yonatankarp
社区

arch-strangler-fig

Use when migrating a legacy system incrementally — phrases like "strangler fig", "strangler pattern", "incremental migration", "monolith to microservices", "rewrite without big bang", "replace legacy in place", "facade in front of the legacy system", "anticorruption layer". Defines Fowler's Strangler Fig as the migration discipline of gradually replacing legacy functionality behind a stable facade, never doing a big-bang rewrite.

安装量
2
GitHub Stars
1
最近更新
5月19日