Skills: Advanced Design Patterns
Last updated: 2026-08-31
Design patterns aren't just for code — the same wisdom in prompt engineering makes Skills more flexible and robust.
1. Strategy Pattern
(1) Concept
Select different execution strategies based on different conditions:
TEXT
📖 Display only
Strategy Pattern Structure
┌──────────┐
│ Context │ → Evaluate conditions → Select strategy
└────┬─────┘
├── Strategy A (Python project)
├── Strategy B (TypeScript project)
└── Strategy C (Go project)
(2) Skill Implementation
MARKDOWN
## Review Strategy Selection
Automatically select based on project tech stack:
{{#if tech_stack == "python"}}
Execute Python review strategy:
- Check type hints
- Check docstrings
- Check PEP 8 compliance
{{/if}}
{{#if tech_stack == "typescript"}}
Execute TypeScript review strategy:
- Check any types
- Check interface definitions
- Check type safety
{{/if}}
(3) Use Cases
| Scenario | Strategy Dimension | Example |
|---|---|---|
| Multi-language project | Programming language | Python/TS/Go review |
| Multi-environment deploy | Target environment | staging/production strategy |
| Multi-framework project | Web framework | React/Vue/Svelte standards |
2. Chain of Responsibility Pattern
(1) Concept
Multiple processors handle a request in sequence; each decides whether to continue passing it on:
TEXT
📖 Display only
Chain of Responsibility Example
Input → Format Check → Security Check → Performance Check → Output
↓ Failed ↓ Failed ↓ Failed
Return error Return error Return error
(2) Skill Implementation
MARKDOWN
## Code Review Chain of Responsibility
### First Gate: Format Check
- Is file encoding correct
- Does code style meet standards
- Format fails → Return format issues, don't continue
### Second Gate: Security Check
- SQL injection, XSS detection
- Hardcoded key detection
- Security fails → Return security issues, don't continue
### Third Gate: Quality Check
- Function length, cyclomatic complexity
- Duplicate code detection
- Quality fails → Return quality issues
### All pass → Output review passed report
(3) Advantages
TEXT
📖 Display only
Chain of Responsibility Advantages
├── Early exit: Previous check failure returns immediately, saving subsequent overhead
├── Separation of concerns: Each checker focuses only on its own dimension
├── Extensible: Add new check dimensions by adding one link
└── Configurable: Can skip certain check links
3. Observer Pattern
(1) Concept
When an event occurs, automatically notify all subscribers:
TEXT
📖 Display only
Observer Pattern
Event source: File change
├── Observer A: Auto-run tests
├── Observer B: Auto code review
└── Observer C: Auto-update docs
(2) Skill Implementation
YAML
---
name: file-change-watcher
description: "File change triggers automatic actions"
triggers:
- context: "file_modified"
---
MARKDOWN
## Change Response Rules
Automatically determine on file change:
- Change src/**/*.py → Trigger Python tests
- Change src/**/*.ts → Trigger TypeScript tests
- Change docs/** → Trigger doc validation
- Change .env* → Remind to check environment config
4. Template Method Pattern
(1) Concept
Define algorithm skeleton; sub-steps can be customized:
MARKDOWN
## Review Template Method
### Fixed Skeleton
1. Collect changes
2. File-by-file review (← Customizable)
3. Aggregate report
4. Output recommendations
### Customizable Step (Step 2)
Customize review dimensions by language/project type
(2) Skill Composition Implementation
TEXT
📖 Display only
Template Method = Base Skill + Pluggable Sub-Skill
base-review.md (skeleton)
├── Collect changes
├── Call {{review_strategy}} Skill (pluggable)
├── Aggregate report
└── Output recommendations
python-review.md (concrete strategy) → Fill into review_strategy
ts-review.md (concrete strategy) → Fill into review_strategy
5. Decorator Pattern
(1) Concept
Dynamically add extra capabilities to a Skill without modifying the original logic:
TEXT
📖 Display only
Base Skill: code-review
├── + Cache decorator: Cache review results
├── + Logging decorator: Record review operations
└── + Notification decorator: Notify team when review completes
(2) Skill Implementation
MARKDOWN
## Enhanced Review Skill
Beyond the basic review flow, add:
1. Before review: Log review request and timestamp
2. After review: Send results to team channel
3. Cache: Reuse last results for unchanged files
❓ FAQ
Q Are design patterns useful in prompts?
A Yes. The essence of patterns is experience in solving specific problems. Using pattern thinking to organize logic in prompts makes output more predictable and maintainable.
Q Which pattern should I use?
A Depends on the problem type — multiple strategies → strategy pattern, pipeline → chain of responsibility, event response → observer, process skeleton → template method.
Q Do patterns make Skills more complex?
A Overuse does. Use at most 1-2 patterns per Skill. Simple problems don't need patterns.
📖 Summary
- Strategy pattern: Select execution strategy based on conditions (multi-language/multi-environment)
- Chain of responsibility: Multiple processors in sequence, fail-fast early exit
- Observer pattern: Event-triggered auto-notification and response
- Template method pattern: Fixed skeleton + customizable sub-steps
- Decorator pattern: Dynamic enhancement without modifying original logic
📝 Exercises
- Basic (⭐): Refactor your review Skill using the strategy pattern, supporting review strategies for 2 programming languages.
- Intermediate (⭐⭐): Design a three-gate review Skill using the chain of responsibility pattern (format→security→quality).
- Advanced (⭐⭐⭐): Comprehensively apply 2+ patterns to design an intelligent review system supporting strategy selection, chain of responsibility checks, and auto-notification.