design-patterns
Skill3 starsChanged 8 months agoCC0-1.0View on GitHub
Enforces correct application of software design patterns including all 23 Gang of Four patterns and modern additions. Use when selecting a creational, structural, or behavioral pattern, evaluating whether a pattern is appropriate, refactoring toward patterns, reviewing code for pattern-itis or over-engineering, or deciding between pattern-based and language-native solutions.
33 other projects use a version of this.
Adopted by
Most recently taken up by
- thistleknot/skillstheir own version, first seen Nov 8, 2026
- gustaferiksson/skillstheir own version, first seen Nov 7, 2026
- alexandrecsp/skillstheir own version, first seen Nov 1, 2026
- cookieMonsterDev/agents-skillstheir own version, first seen Nov 1, 2026
- decebals/claude-code-javatheir own version, first seen Nov 1, 2026
- ralvarez-ai/ralvaskillstheir own version, first seen Nov 1, 2026
Used with
Projects with it also use logging-patterns, tdd-rust and 8 more.
Other files people use alongside this one.
Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
DIL8654Skilllogging-patterns
Keep logs structured, correlated, low-noise, and safe for production support. Use when adding operational logging, reviewing observability, or improving diagnostics in .NET services.
Also in 7 projects that use this
FlorianBruniauxSkilltdd-rust
Also in 3 projects that use this
mstuder-slalomSkilljpa-patterns
JPA/Hibernate patterns for entity design, relationships, query optimization, transactions, auditing, indexing, pagination, and pooling in Spring Boot.
Also in 6 projects that use this
ufodev-ioSkillsecurity-guardian
Comprehensive security layer for all interactions with Claude: audits code, dependencies, commands, configs, and AI-generated output for vulnerabilities. Protects against prompt injection, data leaks, unsafe advice, and social engineering. Works in Cursor, Claude Code, claude.ai, and API contexts. Use always as a background security protocol in any Claude-powered environment.
Also in 3 projects that use this
DIL8654Skillapi-contract-review
Review ASP.NET Core Web API contracts for HTTP semantics, versioning, backward compatibility, and response consistency. Use when the user asks to review an API, check endpoints, validate REST behavior, or before releasing contract changes.
Also in 3 projects that use this
zavierSkilljava-code-review
Java代码审查技能,通过比较两个git分支进行自动化代码审查
Also in 3 projects that use this
Other versions33 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 33
- rtk-ai/rtk★ 86ksame name
- piomin/claude-ai-spring-boot★ 1.4ksame name
- decebals/claude-code-java★ 763same name
- waybarrios/opencode-power-pack★ 547same name
- FlorianBruniaux/ccboard★ 94same name
- nimadorostkar/Claude-Skills-collection★ 33same name
- DIL8654/claude-code-dotnet-template★ 8same name
- tstapler/dotfiles★ 8same name
- cookieMonsterDev/agents-skills★ 7same name
- piomin/claude-ai-quarkus★ 7same name
23 more not listed
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository48 other files it gives its agents.
- 3d-printingSkill
- app-securitySkill
- architecture-designSkill
- aws-genai-lensSkill
- aws-well-architected-frameworkSkill
- aws-well-architectedSkill
- azure-well-architectedSkill
- blog-post-with-diagramsSkill
- clean-architectureSkill
- clean-codeSkill
- databricks-genie-spaces-best-practicesSkill
- data-visualization-guideSkill
- design-an-interfaceSkill
- domain-driven-designSkill
- dry-principleSkill
- edit-articleSkill
- event-driven-designSkill
- git-best-practicesSkill
- git-guardrails-claude-codeSkill
- grill-meSkill
- hexagonal-architectureSkill
- improve-codebase-architectureSkill
- language-conventions-source-en-docs-brSkill
- learn-electronicsSkill
- linked-dataSkill
- microservices-skillSkill
- object-oriented-programmingSkill
- oop-design-patternsSkill
- oreilly-design-referenceSkill
- organize-docs-from-zipSkill
- prd-to-issuesSkill
- prd-to-planSkill
- project-context-syncSkill
- request-refactor-planSkill
- rfc2119Skill
- scaffold-exercisesSkill
- semverSkill
- setup-pre-commitSkill
- solid-principlesSkill
- tddSkill
- todoSkill
- triage-issueSkill
- ts-otp-awsSkill
- ubiquitous-languageSkill
- ux-design-principlesSkill
- write-a-prdSkill
- write-a-skillSkill
- yagni-principleSkill
The file
Show its rules and text
We split this skill into the rules it gives an agent
18 rules. 0 are common, 18 are distinctive, and 0 are very specific to this project.
0
Common
Most of the 32 edited versions we read keep these.
18
Distinctive
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 22
Every pattern decision MUST be guided by these two principles:
- Distinctive: line 41
MUST NOT use Singleton in new code — use dependency injection to manage single-instance lifecycle externally
- Distinctive: line 42
SHOULD prefer Builder over telescoping constructors when an object has 4+ configuration options
- Distinctive: line 43
SHOULD use Factory Method or Abstract Factory when the concrete type is a decision that should be deferred
- Distinctive: line 61
SHOULD use Adapter as the primary pattern for integrating external systems
- Distinctive: line 62
SHOULD prefer Decorator over inheritance for optional, combinable behavior
- Distinctive: line 63
MUST separate intrinsic (shared) from extrinsic (contextual) state when applying Flyweight
- Distinctive: line 85
SHOULD prefer Strategy over Template Method — composition over inheritance
- Distinctive: line 86
SHOULD use language-native constructs (iterators, lambdas, reactive streams) before implementing Iterator, Strategy, or Observer manually
- Distinctive: line 87
MUST evaluate whether the pattern adds value beyond what the language provides natively
- Distinctive: line 107
MUST NOT apply a pattern when only one implementation exists and no variation is foreseeable
- Distinctive: line 108
MUST NOT use a pattern the team does not understand — it becomes accidental complexity
- Distinctive: line 109
SHOULD NOT apply patterns preemptively — refactor *toward* patterns when complexity emerges (Kerievsky)
- Distinctive: line 110
SHOULD start with the simplest thing that works.
- Distinctive: line 117
Check if a language feature solves it natively (generics, lambdas, protocols, pattern matching)
- Distinctive: line 118
If not, select the pattern whose intent matches the problem
- Distinctive: line 120
Verify the pattern improves readability and maintainability for the team
- Distinctive: line 126
Before applying or recommending a pattern, verify:
“Common” is measured: kept by at least 6 in 10 of the 32 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Design Patterns
Reference: Design Patterns (GoF), Head First Design Patterns (Freeman & Robson), Refactoring to Patterns (Kerievsky)
When to Apply
- Selecting a pattern for a recurring design problem
- Refactoring code that exhibits a known code smell toward a pattern
- Reviewing whether an applied pattern is justified or over-engineered
- Deciding if a language feature (lambdas, protocols, generics) eliminates the need for a pattern
- Communicating design intent using shared pattern vocabulary
The Two GoF Maxims
Every pattern decision MUST be guided by these two principles:
- Program to an interface, not an implementation — depend on abstractions; swap implementations without changing clients
- Favor object composition over class inheritance — assemble behavior from collaborating objects rather than building class trees
Creational Patterns
Select based on what varies in object creation:
| Pattern | Intent | Use When | Avoid When |
| Abstract Factory | Create families of related objects without specifying concrete classes | Multiple product families must be interchangeable (e.g., UI themes, platform adapters) | Only one product family exists |
| Builder | Separate construction of complex objects from representation | Object has many optional parameters or multi-step construction | Constructor with 1–3 required params suffices |
| Factory Method | Let subclasses decide which class to instantiate | The exact type depends on runtime context or configuration | A simple constructor call is clear enough |
| Prototype | Create objects by cloning an existing instance | Creating from scratch is expensive or involves complex setup | Object graphs are simple and cheap to construct |
| Singleton | Ensure one instance with global access | Almost never — prefer DI container-managed lifecycle | Testing, concurrency, or coupling matter (most cases) |
- MUST NOT use Singleton in new code — use dependency injection to manage single-instance lifecycle externally
- SHOULD prefer Builder over telescoping constructors when an object has 4+ configuration options
- SHOULD use Factory Method or Abstract Factory when the concrete type is a decision that should be deferred
Structural Patterns
Select based on how objects and classes are composed:
| Pattern | Intent | Use When | Avoid When |
| Adapter | Convert an incompatible interface into one clients expect | Integrating third-party code or legacy systems | You control both interfaces and can change one |
| Bridge | Decouple abstraction from implementation so both vary independently | Two orthogonal dimensions of variation (e.g., shape × renderer) | Only one dimension varies |
| Composite | Treat individual objects and compositions uniformly as a tree | Recursive part-whole hierarchies (file systems, UI components, org charts) | The structure is flat, not tree-shaped |
| Decorator | Attach behavior dynamically without subclassing | Adding optional, combinable responsibilities at runtime | Behavior is always required — just put it in the class |
| Facade | Simplified interface to a complex subsystem | Clients need a streamlined entry point; subsystem internals should be hidden | The subsystem is already simple |
| Flyweight | Share fine-grained objects to save memory | Thousands of similar objects with shared intrinsic state | Object count is small; optimization is premature |
| Proxy | Surrogate controlling access (lazy loading, caching, protection, remote) | Access control, expensive initialization, or cross-network access | Direct access has no cost or risk |
- SHOULD use Adapter as the primary pattern for integrating external systems
- SHOULD prefer Decorator over inheritance for optional, combinable behavior
- MUST separate intrinsic (shared) from extrinsic (contextual) state when applying Flyweight
Behavioral Patterns
Select based on how objects communicate and assign responsibility:
| Pattern | Intent | Use When | Avoid When |
| Chain of Responsibility | Pass request along a chain until handled | Middleware pipelines, event processing, validation chains | A single handler always processes the request |
| Command | Encapsulate a request as an object | Undo/redo, queuing, logging, transaction replay | The action is simple and needs no history |
| Interpreter | Define grammar and interpret sentences | Small, domain-specific languages (query filters, rules engines) | The grammar is complex — use a parser generator |
| Iterator | Sequential access without exposing internals | Built into virtually all modern languages — rarely implement manually | Language-native iteration exists |
| Mediator | Centralize complex inter-object communication | Many objects with complex, many-to-many interactions | Objects have simple, direct relationships |
| Memento | Capture and restore state without breaking encapsulation | Undo, snapshots, time-travel debugging | State is trivial to reconstruct |
| Observer | Notify dependents when state changes | Event-driven systems, reactive UI, pub-sub | Use framework-native reactive patterns (RxJS, signals, hooks) |
| State | Alter behavior when internal state changes | Object behaves differently in distinct states with defined transitions | A simple if/else on one flag suffices |
| Strategy | Interchangeable algorithm family | Multiple algorithms for the same task, selected at runtime | In FP languages, just pass a lambda/function |
| Template Method | Algorithm skeleton with overridable steps | Fixed workflow with varying steps across subclasses | Composition with Strategy achieves the same without inheritance |
| Visitor | Add operations to elements without modifying their classes | New operations are frequent; element types are stable | Element hierarchy changes often — every Visitor breaks |
- SHOULD prefer Strategy over Template Method — composition over inheritance
- SHOULD use language-native constructs (iterators, lambdas, reactive streams) before implementing Iterator, Strategy, or Observer manually
- MUST evaluate whether the pattern adds value beyond what the language provides natively
Modern Patterns Beyond GoF
| Pattern | Intent | Context |
| Dependency Injection | Supply dependencies externally rather than creating them internally | Enables testing, decoupling, and DIP compliance |
| Null Object | Provide a no-op implementation instead of null checks | Eliminates if (x != null) scattered through code |
| Repository | Collection-like interface for aggregate persistence | DDD — one repository per aggregate root |
| Unit of Work | Coordinate writes across repositories in a single transaction | Ensuring consistency across multiple aggregates |
| Specification | Composable, reusable business rule objects | Complex query/validation logic that must be combined |
When NOT to Use Patterns
Pattern-itis — applying patterns speculatively — is worse than the problems patterns solve.
- MUST NOT apply a pattern when only one implementation exists and no variation is foreseeable
- MUST NOT use a pattern the team does not understand — it becomes accidental complexity
- SHOULD NOT apply patterns preemptively — refactor toward patterns when complexity emerges (Kerievsky)
- SHOULD start with the simplest thing that works; introduce a pattern when the code smell appears
Norvig's observation: 16 of 23 GoF patterns are simplified or eliminated by dynamic language features. Before applying a pattern, ask: "Does my language already solve this?"
Decision Flow
- Identify the specific code smell or design problem
- Check if a language feature solves it natively (generics, lambdas, protocols, pattern matching)
- If not, select the pattern whose intent matches the problem
- Apply the simplest form of the pattern — avoid gold-plating
- Verify the pattern improves readability and maintainability for the team
Checklist
Before applying or recommending a pattern, verify:
- A specific, recurring problem has been identified (not speculative future need)
- Language-native features have been considered first
- The selected pattern's intent matches the actual problem
- The pattern improves — not hinders — code readability for the team
- Singleton is NOT used (DI container manages lifecycle instead)
- Composition-based patterns are preferred over inheritance-based ones
- The pattern is applied in its simplest form without unnecessary abstraction layers
- The code compiles and passes tests after applying the pattern
Key References
| Book | Author(s) | Publisher | Year |
| Design Patterns: Elements of Reusable OO Software | Gamma, Helm, Johnson, Vlissides | Addison-Wesley | 1994 |
| Head First Design Patterns (2nd ed.) | Freeman & Robson | O'Reilly | 2021 |
| Patterns of Enterprise Application Architecture | Martin Fowler | Addison-Wesley | 2002 |
| Refactoring to Patterns | Joshua Kerievsky | Addison-Wesley | 2004 |
| Dive Into Design Patterns | Alexander Shvets | Refactoring.Guru | 2021 |
| Game Programming Patterns | Robert Nystrom | Genever Benning | 2014 |
| Fundamentals of Software Architecture | Mark Richards, Neal Ford | O'Reilly | 2020 |
| Software Architecture: The Hard Parts | Ford, Richards, Sadalage, Dehghani | O'Reilly | 2021 |
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.

