agentleFS
luckysluckys/agent-skills/skills/design-patterns-best-practices/SKILL.md

design-patterns-best-practices

Skill5 starsChanged 30 days agoMITView on GitHub

Use when selecting or reviewing GoF, enterprise, Criteria, or Clean Architecture patterns. Compare the current change pressure with a direct solution and assess coupling, interface cost, and fit; use the OOP skill for routine object design.

The file

Show its rules and text

We split this skill into the rules it gives an agent

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

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈19

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 19

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Use this skill when the main question is not just code quality, but pattern choice and pattern fit.

    line 12
  2. Distinctive:

    Start from the problem shape, not from pattern names.

    line 16
  3. Distinctive:

    Prefer the smallest pattern that clarifies variation or collaboration.

    line 17
  4. Distinctive:

    Keep the domain language more visible than the pattern vocabulary.

    line 19
  5. Distinctive:

    Remove or avoid patterns that explain less than the code they replace.

    line 20
  6. Distinctive:

    Stop if the pattern is heavier than the problem.

    line 45
  7. Distinctive:

    Use when behavior varies by policy or algorithm and should be swappable.

    line 51
  8. Distinctive:

    Use when the same object changes behavior as it transitions through states and the transition rules matter.

    line 55
  9. Distinctive:

    Use when creation logic is complex, repeated, or hides meaningful variation.

    line 59
  10. Distinctive:

    Use when external APIs do not match the internal model you want.

    line 63
  11. Distinctive:

    Use when behavior needs to be layered without changing the underlying contract.

    line 67
  12. Distinctive:

    Use when leaf and group objects should answer the same messages.

    line 71
  13. Distinctive:

    Use when one object's state change should trigger reactions in other objects without the source knowing who is listening.

    line 75
  14. Distinctive:

    Use when you need to decouple the sender of a request from its executor, or when requests need to be queued, logged, or undone.

    line 79
  15. Distinctive:

    Use when multiple classes share the same algorithm skeleton but differ in specific steps — and the skeleton should not be changed by …

    line 83
  16. Distinctive:

    Use when constructing a complex object requires many steps, optional parts, or a specific construction order.

    line 87
  17. Distinctive:

    Use when you need a surrogate for another object — to defer creation (virtual), control access (protection), or represent a remote resource …

    line 91
  18. Distinctive:

    Use when a complex subsystem needs a simplified interface for callers who don't need its full detail.

    line 95
  19. Distinctive:

    Use when you want to decouple business logic from data access and treat a collection of objects as if it were in memory.

    line 99
  20. Very specific:

    Use ddd-best-practices when the main decision is Aggregate repository semantics, contract ownership, or Repository vs DAO/query …

    line 101
  21. Very specific:

    Read references/pattern-fit-evidence.md when comparing a pattern with a direct solution or checking whether a new seam earns its cost.

    line 113
  22. Very specific:

    Read references/pattern-selection-guide.md for pattern-to-problem mapping.

    line 115
  23. Very specific:

    Read references/composition-vs-inheritance.md for structural trade-offs.

    line 116
  24. Very specific:

    Read references/language-examples.md for an index of language-specific example files (TypeScript, Java, Python, C#, Ruby, PHP, Go, Rust).

    line 117
  25. Very specific:

    Read references/go-examples.md for Go examples (Strategy/State via interfaces, functional options as Builder, channels as Observer, Result …

    line 118
  26. Very specific:

    Read references/rust-examples.md for Rust examples (traits as Strategy, enums as State/Visitor, trait objects for DI, Result<T,E>).

    line 119
  27. Very specific:

    Read references/behavioral-patterns.md for Observer, Command, Template Method, Chain of Responsibility, Iterator, Mediator, Visitor, and …

    line 120
  28. Very specific:

    Read references/creational-patterns.md for Builder, Abstract Factory, Factory Method, Singleton, and Prototype trade-offs.

    line 121
  29. Very specific:

    Read references/structural-patterns.md for Proxy, Facade, Bridge, Flyweight, and Adapter — including the Facade vs Adapter distinction.

    line 122
  30. Very specific:

    Read references/enterprise-patterns.md for all 51 PoEAA patterns grouped by category: Domain Logic, Data Source, ORM Behavioral/Structural, …

    line 123
  31. Very specific:

    Read references/patterns-in-practice.md for practical heuristics on refactoring toward patterns, Observer lessons, Command Bus, Result …

    line 124
  32. Very specific:

    Read references/implementation-patterns.md for Kent Beck's micro-level code patterns: naming, composed methods, guard clauses, value …

    line 125
  33. Very specific:

    Read references/clean-architecture.md for Clean Architecture layers (Entities, Use Cases, Interface Adapters, Frameworks), the Dependency …

    line 126
  34. Very specific:

    Read references/criteria-pattern.md for Criteria/query-object decisions, typed predicate ASTs, logical field mappings, backend …

    line 127
  35. Very specific:

    Use oop-best-practices for everyday code quality choices.

    line 131
  36. Very specific:

    Use refactoring-best-practices when applying a pattern inside risky existing code.

    line 132
  37. Very specific:

    Use rest-api-best-practices when applying patterns at the HTTP API boundary (Adapter, DTO, Result, Repository).

    line 133
  38. Very specific:

    Use ddd-best-practices for Aggregate-oriented repository contracts and persistence boundaries.

    line 134

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 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

Design Patterns Best Practices

Use this skill when the main question is not just code quality, but pattern choice and pattern fit.

Working Style

  1. Start from the problem shape, not from pattern names.
  2. Prefer the smallest pattern that clarifies variation or collaboration.
  3. Introduce patterns to reduce coupling and change cost, not to impress readers.
  4. Keep the domain language more visible than the pattern vocabulary.
  5. Remove or avoid patterns that explain less than the code they replace.

Pattern Selection Workflow

  1. Identify the pressure.
    • Is the problem construction complexity?
    • Is it behavior variation?
    • Is it state-dependent behavior?
    • Is it external integration mismatch?
    • Is it optional layered behavior?
  2. Choose the likely pattern family.
    • Strategy for algorithm or policy variation
    • State for behavior driven by state transitions
    • Factory for meaningful construction
    • Adapter for external interface mismatch
    • Decorator for composable behavior layers
    • Composite for tree-shaped structures with uniform treatment
  3. Check the fit.
    • Does the pattern remove duplication of knowledge?
    • Does it make change local?
    • Does it improve object collaboration more than a small refactor would?
    • Can the team read it easily?
  4. Stop if the pattern is heavier than the problem.

Pattern Heuristics

Strategy

Use when behavior varies by policy or algorithm and should be swappable.

State

Use when the same object changes behavior as it transitions through states and the transition rules matter.

Factory

Use when creation logic is complex, repeated, or hides meaningful variation.

Adapter

Use when external APIs do not match the internal model you want.

Decorator

Use when behavior needs to be layered without changing the underlying contract.

Composite

Use when leaf and group objects should answer the same messages.

Observer

Use when one object's state change should trigger reactions in other objects without the source knowing who is listening.

Command

Use when you need to decouple the sender of a request from its executor, or when requests need to be queued, logged, or undone.

Template Method

Use when multiple classes share the same algorithm skeleton but differ in specific steps — and the skeleton should not be changed by subclasses.

Builder

Use when constructing a complex object requires many steps, optional parts, or a specific construction order.

Proxy

Use when you need a surrogate for another object — to defer creation (virtual), control access (protection), or represent a remote resource (remote).

Facade

Use when a complex subsystem needs a simplified interface for callers who don't need its full detail.

Repository

Use when you want to decouple business logic from data access and treat a collection of objects as if it were in memory.

Use ddd-best-practices when the main decision is Aggregate repository semantics, contract ownership, or Repository vs DAO/query service/gateway.

Warning Signs

  • The pattern vocabulary dominates the domain language.
  • A simple extraction would solve the problem just as well.
  • The pattern creates many classes but leaves the coupling intact.
  • Inheritance is used where composition would isolate variation better.
  • The team has to understand the pattern before it can understand the business rule.

References

  • Read references/pattern-fit-evidence.md when comparing a pattern with a direct solution or checking whether a new seam earns its cost.
  • Read references/pattern-selection-guide.md for pattern-to-problem mapping.
  • Read references/composition-vs-inheritance.md for structural trade-offs.
  • Read references/language-examples.md for an index of language-specific example files (TypeScript, Java, Python, C#, Ruby, PHP, Go, Rust).
  • Read references/go-examples.md for Go examples (Strategy/State via interfaces, functional options as Builder, channels as Observer, Result via (value, error)).
  • Read references/rust-examples.md for Rust examples (traits as Strategy, enums as State/Visitor, trait objects for DI, Result<T,E>).
  • Read references/behavioral-patterns.md for Observer, Command, Template Method, Chain of Responsibility, Iterator, Mediator, Visitor, and Memento.
  • Read references/creational-patterns.md for Builder, Abstract Factory, Factory Method, Singleton, and Prototype trade-offs.
  • Read references/structural-patterns.md for Proxy, Facade, Bridge, Flyweight, and Adapter — including the Facade vs Adapter distinction.
  • Read references/enterprise-patterns.md for all 51 PoEAA patterns grouped by category: Domain Logic, Data Source, ORM Behavioral/Structural, Web Presentation, Distribution, Concurrency, Session State, and Base Patterns.
  • Read references/patterns-in-practice.md for practical heuristics on refactoring toward patterns, Observer lessons, Command Bus, Result pattern, and DI container internals.
  • Read references/implementation-patterns.md for Kent Beck's micro-level code patterns: naming, composed methods, guard clauses, value objects, lazy/eager initialization, collection accessors, and method objects.
  • Read references/clean-architecture.md for Clean Architecture layers (Entities, Use Cases, Interface Adapters, Frameworks), the Dependency Rule, Ports & Adapters, Skinny Controllers, and SOLID as architecture enablers.
  • Read references/criteria-pattern.md for Criteria/query-object decisions, typed predicate ASTs, logical field mappings, backend capabilities, SQL parameterization, joins, pagination, boundary translation, and adapter testing.

Related Skills

  • Use oop-best-practices for everyday code quality choices.
  • Use refactoring-best-practices when applying a pattern inside risky existing code.
  • Use rest-api-best-practices when applying patterns at the HTTP API boundary (Adapter, DTO, Result, Repository).
  • Use ddd-best-practices for Aggregate-oriented repository contracts and persistence boundaries.

Source Influences

This skill is synthesized from ideas emphasized in:

  • Head First Design Patterns
  • Drive Into Design Patterns
  • Practical Object-Oriented Design in Ruby by Sandi Metz
  • Implementation Patterns by Kent Beck
  • CodelyTV Criteria Pattern course (including multi-backend and security counterexamples)

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.