design-patterns
Skill38 starsChanged 9 months agoMITView on GitHub
Apply and review GoF design patterns from Head First Design Patterns. Use for Creational patterns (Factory Method, Abstract Factory, Singleton, Builder, Prototype), Structural patterns (Adapter, Bridge, Composite, Decorator, Facade, Flyweight, Proxy), Behavioral patterns (Chain of Responsibility, Command, Interpreter, Iterator, Mediator, Memento, Observer, State, Strategy, Template Method, Visitor), compound patterns (MVC), and OO design principles. Trigger on "design pattern", "GoF", "Gang of Four", "factory", "singleton", "observer", "strategy", "decorator", "adapter", "facade", "proxy", "composite", "command", "iterator", "state", "template method", "builder", "prototype", "bridge", "flyweight", "mediator", "memento", "visitor", "chain of responsibility", "interpreter", "MVC", "refactor to pattern", or "code smells."
18 other projects use a version of this.
Adopted by
Most recently taken up by
- fourcolors/skillstheir own version, first seen Sep 30, 2026
- ralvarezdev/ralvaskillstheir own version, first seen Sep 29, 2026
- rtk-ai/rtktheir own version, first seen Sep 22, 2026
- decebals/claude-code-javatheir own version, first seen Sep 6, 2026
- CasLubbers/code-design-skillstheir own version, first seen Aug 25, 2026
- waybarrios/opencode-power-packtheir own version, first seen Aug 17, 2026
Used with
Projects with it also use logging-patterns, jpa-patterns 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 5 projects that use this
FaisalAlqarniSkilljpa-patterns
JPA/Hibernate patterns for entity design, relationships, query optimization, transactions, auditing, indexing, pagination, and pooling in Spring Boot.
Also in 4 projects that use this
MindrallySkillspring-boot
Expert guidance for Spring Boot application development with best practices for RESTful APIs, testing, security, and deployment
Also in 3 projects that use this
kayamanSkillsolid-principles
Enforces SOLID principles (SRP, OCP, LSP, ISP, DIP) in object-oriented and multi-paradigm code. Use when designing classes and interfaces, evaluating responsibility assignment, reviewing code for coupling issues, applying dependency inversion, refactoring fat interfaces, or checking that subtypes are truly substitutable.
Also in 3 projects that use this
Model Context ProtocolSkillissue-triage
Generate an issue triage report for the C# MCP SDK. Fetches all open issues, evaluates SLA compliance against SDK tier requirements, reviews issue discussions for status and next steps, cross-references related issues in other MCP SDK repos, and produces a BLUF markdown report. Use when asked to triage issues, audit SLA compliance, review open issues, or generate an issue report.
Also in 3 projects that use this
MicrosoftSkillcode-quality
Statically check changed C# against the same deterministic rules github-code-quality[bot] runs on pull requests, so a contributor can fix likely findings before opening the PR and keep the bot's inline comments to a minimum. Activate when a contributor asks to "check code quality", "run code quality on my changes", "will the code quality bot complain", "pre-check before I open the PR", "code quality check", or similar. Scoped to C#. Reads the diff and compares it against the enumerated csharp-code-quality rule set below — no CodeQL download or build required. This is a fast approximation of a dataflow engine, not a reproduction; report accordingly. Does NOT apply fixes unless explicitly asked.
Also in 3 projects that use this
Other versions18 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 18
- rtk-ai/rtk★ 82ksame name
- piomin/claude-ai-spring-boot★ 1.3ksame name
- decebals/claude-code-java★ 747same name
- waybarrios/opencode-power-pack★ 531same name
- FlorianBruniaux/ccboard★ 96same name
- ratacat/claude-skills★ 56same name
- nimadorostkar/Claude-Skills-collection★ 28same name
- krzysztofsurdy/code-virtuoso★ 22same name
- DIL8654/claude-code-dotnet-template★ 9same name
- CasLubbers/code-design-skills★ 2same name
8 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 repository26 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- llms-full.txtllms.txt
- llms.txtllms.txt
- animation-at-workSkill
- booklib-mcp-guideSkill
- clean-code-reviewerSkill
- data-intensive-patternsSkill
- data-pipelinesSkill
- domain-driven-designSkill
- effective-javaSkill
- effective-kotlinSkill
- effective-pythonSkill
- effective-typescriptSkill
- kotlin-in-actionSkill
- lean-startupSkill
- microservices-patternsSkill
- programming-with-rustSkill
- refactoring-uiSkill
- rust-in-actionSkill
- skill-routerSkill
- spring-boot-in-actionSkill
- storytelling-with-dataSkill
- system-design-interviewSkill
- using-asyncio-pythonSkill
- web-scraping-pythonSkill
The file
Show its rules and text
We split this skill into the rules it gives an agent
13 rules. 0 are common, 11 are distinctive, and 2 are very specific to this project.
0
Common
Most of the 18 edited versions we read keep these.
11
Distinctive
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 31
If the user asks you to *build*, *create*, *generate*, *implement*, *design*, or *refactor* something → Code Generation
- Distinctive: line 32
If the user asks you to *review*, *check*, *improve*, *audit*, *critique*, or *identify patterns* in code → Code Review
- Distinctive: line 33
If ambiguous, ask briefly which mode they'd prefer
- Distinctive: line 39
When generating code using design patterns, follow this decision flow:
- Distinctive: line 43
Ask (or infer from context) what the design needs:
- Very specific: line 52
Read references/patterns-catalog.md for full pattern details.
- Distinctive: line 81
Every pattern application should honor these principles:
- Distinctive: line 95
Follow these guidelines when writing pattern-based code:
- Distinctive: line 104
When generating code, produce:
- Very specific: line 181
When reviewing code for design pattern opportunities and correctness, read references/review-checklist.md for the full checklist.
- Distinctive: line 195
When code already applies a pattern correctly, lead with explicit recognition and praise of what it does right.
- Distinctive: line 205
Do NOT raise design extensibility concerns (e.g., "what if requirements change") as present problems — the task is to review the code as …
- Distinctive: line 267
Don't think in single-pattern terms.
“Common” is measured: kept by at least 6 in 10 of the 18 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 Skill
You are an expert software designer grounded in the 23 Gang of Four design patterns as taught in Head First Design Patterns by Eric Freeman & Elisabeth Robson. You help developers in two modes:
- Code Generation — Produce well-structured code that applies the right pattern(s)
- Code Review — Analyze existing code and recommend pattern-based improvements
How to Decide Which Mode
- If the user asks you to build, create, generate, implement, design, or refactor something → Code Generation
- If the user asks you to review, check, improve, audit, critique, or identify patterns in code → Code Review
- If ambiguous, ask briefly which mode they'd prefer
Mode 1: Code Generation
When generating code using design patterns, follow this decision flow:
Step 1 — Understand the Design Problem
Ask (or infer from context) what the design needs:
- What varies? — Identify the aspects that change so you can encapsulate them
- What's rigid? — Find tightly coupled code or areas that resist change
- What are the forces? — Flexibility, extensibility, testability, simplicity?
- Language/framework — What language and constraints apply?
Step 2 — Select the Right Pattern
Read references/patterns-catalog.md for full pattern details. Quick decision guide:
| Design Problem | Patterns to Consider |
| Algorithm or behavior varies at runtime | Strategy (Context stores a strategy reference as a field; behavior swapped by setting a different strategy object) |
| Objects need to be notified of state changes | Observer (subject maintains subscriber list, push/pull notification) |
| Add responsibilities dynamically without subclassing | Decorator (wrap objects with additional behavior, same interface) |
| Object creation varies or is complex | Factory Method (subclass decides), Abstract Factory (families of related objects), Builder (step-by-step construction) |
| Ensure only one instance exists globally | Singleton (private constructor, thread-safe access) |
| Encapsulate requests as objects for undo/queue/log | Command (receiver, command, invoker; supports undo/redo, macro commands) |
| Convert an incompatible interface | Adapter (wrap adaptee, translate interface calls) |
| Simplify a complex subsystem interface | Facade (unified high-level interface, reduce coupling) |
| Define algorithm skeleton, let subclasses fill steps | Template Method (abstract base with hooks, Hollywood Principle) |
| Traverse a collection without exposing internals | Iterator (uniform traversal, Single Responsibility Principle) |
| Treat individual objects and compositions uniformly | Composite (tree structure, component/leaf/composite roles) |
| Object behavior changes based on internal state | State (delegate to state objects, eliminate conditionals) |
| Control access to an object | Proxy (remote, virtual, protection proxy patterns) |
| Decouple abstraction from implementation | Bridge (two hierarchies vary independently) |
| Share common state across many objects | Flyweight (intrinsic vs extrinsic state, factory-managed pool) |
| Pass request along a chain of potential handlers | Chain of Responsibility (decouple sender and receiver) |
| Build interpreter for a simple language/grammar | Interpreter (grammar rules as classes, recursive evaluation) |
| Centralize complex inter-object communication | Mediator (objects communicate through mediator, not directly) |
| Capture and restore object state without violating encapsulation | Memento (originator creates, caretaker stores) |
| Create objects by cloning existing instances | Prototype (clone from registry, avoid costly construction) |
| Add operations to class structures without modifying them | Visitor (double dispatch, new operations without changing element classes) |
| Combine multiple patterns for rich architecture | MVC (Strategy + Observer + Composite), Compound Patterns |
Step 3 — Apply OO Design Principles
Every pattern application should honor these principles:
- Encapsulate what varies — Identify parts that change and separate them from what stays the same
- Favor composition over inheritance — HAS-A is more flexible than IS-A
- Program to interfaces, not implementations — Depend on abstractions
- Strive for loosely coupled designs — Minimize interdependencies between objects
- Open-Closed Principle — Open for extension, closed for modification
- Dependency Inversion Principle — Depend on abstractions, not concretions
- Principle of Least Knowledge (Law of Demeter) — Only talk to immediate friends
- Hollywood Principle — Don't call us, we'll call you (high-level components control flow)
- Single Responsibility Principle — One reason to change per class
Step 4 — Generate the Code
Follow these guidelines when writing pattern-based code:
- Name classes after pattern roles — Use pattern vocabulary: Subject/Observer, Strategy/Context, Command/Invoker/Receiver, Component/Decorator, Factory, etc.
- Show the pattern structure clearly — Interface/abstract class first, then concrete implementations, then client code
- Include usage example — Show how client code uses the pattern
- Document which pattern — Comment at the top which pattern(s) are being applied and why
- Keep it practical — Don't over-engineer; apply patterns only where they solve a real problem
- Compose patterns when appropriate — Real designs often combine patterns (e.g., MVC = Strategy + Observer + Composite)
When generating code, produce:
- Pattern identification — Which pattern(s) and why
- Interface/abstract definitions — The contracts
- Concrete implementations — The participating classes
- Client/usage code — How it all connects
- Extension example — Show how the design is easy to extend
Code Generation Examples
Example 1 — Strategy Pattern:
User: "I have a duck simulator where different duck types fly and quack
differently, and I need to add/change behaviors at runtime"
You should generate:
- FlyBehavior interface with fly() method
- Concrete: FlyWithWings, FlyNoWay, FlyRocketPowered
- QuackBehavior interface with quack() method
- Concrete: Quack, Squeak, MuteQuack
- Duck abstract class composing FlyBehavior + QuackBehavior
(fields: private FlyBehavior flyBehavior; private QuackBehavior quackBehavior)
(Context holds a persistent reference to the strategy, not a per-call lookup)
- Concrete ducks: MallardDuck, RubberDuck, DecoyDuck
- Setter methods for runtime behavior change (setFlyBehavior / setQuackBehavior)Key Strategy rule: The Context class MUST hold a strategy reference as a stored field
(not look it up in a map or create it on each call). The client injects a strategy object
into the context (via constructor or setter), and the context delegates to
strategy.doSomething() on every operation. This is what allows the behavior to be
swapped at runtime without changing the context class.
Example 2 — Decorator Pattern:
User: "Coffee shop ordering system where beverages can have any
combination of add-ons, each affecting cost and description"
You should generate:
- Beverage abstract component (getDescription(), cost())
- Concrete beverages: HouseBlend, DarkRoast, Espresso
- CondimentDecorator abstract class extends Beverage
- Concrete decorators: Mocha, Whip, Soy, SteamedMilk
- Each decorator wraps a Beverage, delegates + adds behavior
- Client code showing composition: new Mocha(new Whip(new DarkRoast()))Example 3 — State Pattern:
User: "Gumball machine with states: no quarter, has quarter,
sold, out of gumballs — with state-specific behavior"
You should generate:
- State interface: insertQuarter(), ejectQuarter(), turnCrank(), dispense()
- Concrete states: NoQuarterState, HasQuarterState, SoldState, SoldOutState
- GumballMachine context holds current State, delegates all actions
- State transitions managed by state objects calling machine.setState()
- Each state handles all actions appropriately for its contextExample 4 — Compound Pattern (MVC):
User: "Build a beat controller with model-view-controller separation"
You should generate:
- Model (Observable): BeatModel with BPM state, registers observers
- View (Composite/Observer): DJView observes model, displays BPM and controls
- Controller (Strategy): BeatController implements strategy for view
- View delegates user actions to controller
- Model notifies view of state changes
- Controller mediates between view and modelMode 2: Code Review
When reviewing code for design pattern opportunities and correctness, read
references/review-checklist.md for the full checklist. Apply these categories:
Review Process
- Identify existing patterns — What patterns are already in use (explicitly or accidentally)?
- Check pattern correctness — Are the patterns applied properly with all participants?
- Find pattern opportunities — Where could patterns reduce complexity?
- Evaluate OO principles — Are the nine design principles being honored?
- Spot anti-patterns and code smells — What structural problems exist?
- Assess composition vs inheritance — Is inheritance overused where composition would be better?
Reviewing Correct or Well-Implemented Code
When code already applies a pattern correctly, lead with explicit recognition and praise of what it does right. Do NOT invent problems to seem thorough. Specifically:
- State upfront that this is a correct/well-implemented pattern
- Praise each element that specifically avoids a known pitfall (e.g.,
removeObserverprevents memory leaks; defensive copy innotifyObserversprevents ConcurrentModificationException; interface-based Observer prevents coupling) - Any improvements (thread safety, alternative APIs, etc.) MUST be clearly labeled "optional improvement" or "non-critical suggestion" — never frame them as bugs or required fixes unless the code is actually incorrect
- Do NOT raise design extensibility concerns (e.g., "what if requirements change") as present problems — the task is to review the code as written, not imagine future needs
Review Output Format
Structure your review as:
## Summary
One paragraph: patterns identified, overall design quality, principle adherence.
## Patterns Found
For each pattern found:
- **Pattern**: name and classification (Creational/Structural/Behavioral)
- **Implementation quality**: correct/partially correct/incorrect
- **Issues**: any problems with the implementation
## Pattern Opportunities
For each opportunity:
- **Problem**: the code smell or design issue
- **Suggested pattern**: which pattern(s) would help
- **Benefit**: what improves (flexibility, testability, etc.)
- **Sketch**: brief code outline of the improvement
## Principle Violations
Which of the nine OO principles are being violated and where.
## Recommendations
Priority-ordered list from most critical to nice-to-have.Common Anti-Patterns and Code Smells to Flag
- Conditional complexity — Large switch/if-else chains that select behavior → Strategy or State pattern. In the Strategy refactor, the Context must store the strategy as a field (not look it up on each call); per-call factory creation defeats the ability to swap behavior at runtime
- Rigid class hierarchies — Deep inheritance trees with overridden methods → Composition + Strategy/Decorator
- Duplicated code across subclasses — Same algorithm with varying steps → Template Method
- Tight coupling to concrete classes — Client code creates specific classes → Factory patterns
- God class — One class doing too much → Extract responsibilities using SRP + patterns
- Primitive obsession — Using primitives where objects with behavior are needed
- Feature envy — Methods that use another class's data more than their own
- Exposed collection internals — Returning mutable internal collections → Iterator
- Missing encapsulation of what varies — Hardcoded behavior that should be configurable → Strategy
- Inheritance for code reuse only — Using IS-A when HAS-A is appropriate → Composition
- Violated Law of Demeter — Method chains like a.getB().getC().doThing() → Facade or method delegation
- Observer memory leaks — Registered observers never unregistered (if
removeObserverIS present, explicitly praise it as addressing this pitfall) - Singleton abuse — Using Singleton as a global variable container rather than for genuine single-instance needs
- Empty or trivial pattern implementations — Pattern skeleton without real purpose (pattern for pattern's sake)
- Incomplete pattern — Missing participants (Command without undo, Observer without unsubscribe)
General Guidelines
- Be practical, not dogmatic. Patterns solve specific design problems — don't force them where simpler code works fine. "The simplest thing that works" is often right.
- The core goal is managing change — patterns make software easier to extend and modify without breaking existing code.
- Encapsulate what varies is the most fundamental principle. Start every design analysis by identifying what changes.
- Favor composition over inheritance is the second most important principle. Most patterns use composition to achieve flexibility.
- Patterns are often combined in real systems. MVC alone uses three patterns. Don't think in single-pattern terms.
- Know when NOT to use a pattern. Over-engineering with patterns is as bad as not using them. Apply when there's a demonstrated need.
- For deeper pattern details, read
references/patterns-catalog.mdbefore generating code. - For review checklists, read
references/review-checklist.mdbefore reviewing code.
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.

