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.
In this repository11 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- boostSkill
- data-migration-best-practicesSkill
- ddd-best-practicesSkill
- flowSkill
- fp-best-practicesSkill
- infrastructure-designSkill
- oop-best-practicesSkill
- refactoring-best-practicesSkill
- rest-api-best-practicesSkill
- tdd-best-practicesSkill
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
- Distinctive: line 12
Use this skill when the main question is not just code quality, but pattern choice and pattern fit.
- Distinctive: line 16
Start from the problem shape, not from pattern names.
- Distinctive: line 17
Prefer the smallest pattern that clarifies variation or collaboration.
- Distinctive: line 19
Keep the domain language more visible than the pattern vocabulary.
- Distinctive: line 20
Remove or avoid patterns that explain less than the code they replace.
- Distinctive: line 45
Stop if the pattern is heavier than the problem.
- Distinctive: line 51
Use when behavior varies by policy or algorithm and should be swappable.
- Distinctive: line 55
Use when the same object changes behavior as it transitions through states and the transition rules matter.
- Distinctive: line 59
Use when creation logic is complex, repeated, or hides meaningful variation.
- Distinctive: line 63
Use when external APIs do not match the internal model you want.
- Distinctive: line 67
Use when behavior needs to be layered without changing the underlying contract.
- Distinctive: line 71
Use when leaf and group objects should answer the same messages.
- Distinctive: line 75
Use when one object's state change should trigger reactions in other objects without the source knowing who is listening.
- Distinctive: line 79
Use when you need to decouple the sender of a request from its executor, or when requests need to be queued, logged, or undone.
- Distinctive: line 83
Use when multiple classes share the same algorithm skeleton but differ in specific steps — and the skeleton should not be changed by …
- Distinctive: line 87
Use when constructing a complex object requires many steps, optional parts, or a specific construction order.
- Distinctive: line 91
Use when you need a surrogate for another object — to defer creation (virtual), control access (protection), or represent a remote resource …
- Distinctive: line 95
Use when a complex subsystem needs a simplified interface for callers who don't need its full detail.
- Distinctive: line 99
Use when you want to decouple business logic from data access and treat a collection of objects as if it were in memory.
- Very specific: line 101
Use ddd-best-practices when the main decision is Aggregate repository semantics, contract ownership, or Repository vs DAO/query …
- Very specific: line 113
Read references/pattern-fit-evidence.md when comparing a pattern with a direct solution or checking whether a new seam earns its cost.
- Very specific: line 115
Read references/pattern-selection-guide.md for pattern-to-problem mapping.
- Very specific: line 116
Read references/composition-vs-inheritance.md for structural trade-offs.
- Very specific: line 117
Read references/language-examples.md for an index of language-specific example files (TypeScript, Java, Python, C#, Ruby, PHP, Go, Rust).
- Very specific: line 118
Read references/go-examples.md for Go examples (Strategy/State via interfaces, functional options as Builder, channels as Observer, Result …
- Very specific: line 119
Read references/rust-examples.md for Rust examples (traits as Strategy, enums as State/Visitor, trait objects for DI, Result<T,E>).
- Very specific: line 120
Read references/behavioral-patterns.md for Observer, Command, Template Method, Chain of Responsibility, Iterator, Mediator, Visitor, and …
- Very specific: line 121
Read references/creational-patterns.md for Builder, Abstract Factory, Factory Method, Singleton, and Prototype trade-offs.
- Very specific: line 122
Read references/structural-patterns.md for Proxy, Facade, Bridge, Flyweight, and Adapter — including the Facade vs Adapter distinction.
- Very specific: line 123
Read references/enterprise-patterns.md for all 51 PoEAA patterns grouped by category: Domain Logic, Data Source, ORM Behavioral/Structural, …
- Very specific: line 124
Read references/patterns-in-practice.md for practical heuristics on refactoring toward patterns, Observer lessons, Command Bus, Result …
- Very specific: line 125
Read references/implementation-patterns.md for Kent Beck's micro-level code patterns: naming, composed methods, guard clauses, value …
- Very specific: line 126
Read references/clean-architecture.md for Clean Architecture layers (Entities, Use Cases, Interface Adapters, Frameworks), the Dependency …
- Very specific: line 127
Read references/criteria-pattern.md for Criteria/query-object decisions, typed predicate ASTs, logical field mappings, backend …
- Very specific: line 131
Use oop-best-practices for everyday code quality choices.
- Very specific: line 132
Use refactoring-best-practices when applying a pattern inside risky existing code.
- Very specific: line 133
Use rest-api-best-practices when applying patterns at the HTTP API boundary (Adapter, DTO, Result, Repository).
- Very specific: line 134
Use ddd-best-practices for Aggregate-oriented repository contracts and persistence boundaries.
≈ “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.
Files
Design Patterns Best Practices
Use this skill when the main question is not just code quality, but pattern choice and pattern fit.
Working Style
- Start from the problem shape, not from pattern names.
- Prefer the smallest pattern that clarifies variation or collaboration.
- Introduce patterns to reduce coupling and change cost, not to impress readers.
- Keep the domain language more visible than the pattern vocabulary.
- Remove or avoid patterns that explain less than the code they replace.
Pattern Selection Workflow
- 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?
- 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
- 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?
- 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.mdwhen comparing a pattern with a direct solution or checking whether a new seam earns its cost. - Read
references/pattern-selection-guide.mdfor pattern-to-problem mapping. - Read
references/composition-vs-inheritance.mdfor structural trade-offs. - Read
references/language-examples.mdfor an index of language-specific example files (TypeScript, Java, Python, C#, Ruby, PHP, Go, Rust). - Read
references/go-examples.mdfor Go examples (Strategy/State via interfaces, functional options as Builder, channels as Observer, Result via(value, error)). - Read
references/rust-examples.mdfor Rust examples (traits as Strategy, enums as State/Visitor, trait objects for DI, Result<T,E>). - Read
references/behavioral-patterns.mdfor Observer, Command, Template Method, Chain of Responsibility, Iterator, Mediator, Visitor, and Memento. - Read
references/creational-patterns.mdfor Builder, Abstract Factory, Factory Method, Singleton, and Prototype trade-offs. - Read
references/structural-patterns.mdfor Proxy, Facade, Bridge, Flyweight, and Adapter — including the Facade vs Adapter distinction. - Read
references/enterprise-patterns.mdfor 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.mdfor practical heuristics on refactoring toward patterns, Observer lessons, Command Bus, Result pattern, and DI container internals. - Read
references/implementation-patterns.mdfor 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.mdfor 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.mdfor 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-practicesfor everyday code quality choices. - Use
refactoring-best-practiceswhen applying a pattern inside risky existing code. - Use
rest-api-best-practiceswhen applying patterns at the HTTP API boundary (Adapter, DTO, Result, Repository). - Use
ddd-best-practicesfor Aggregate-oriented repository contracts and persistence boundaries.
Source Influences
This skill is synthesized from ideas emphasized in:
Head First Design PatternsDrive Into Design PatternsPractical Object-Oriented Design in Rubyby Sandi MetzImplementation Patternsby Kent Beck- CodelyTV Criteria Pattern course (including multi-backend and security counterexamples)
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
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.

