Design pattern
Expert knowledge in software design patterns covering GoF patterns, architectural patterns, and modern design principles. Apply appropriate patterns to improve code maintainability, scalability, and extensibility. Use this skill when designing new software components, refactoring existing code, reviewing code for design quality, resolving complex design problems, or need guidance on applying SOLID principles and identifying code smells.From its SKILL.md
npx -y skills add HK-hub/AgentSkills --skill design-patternAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
One thing to look at
- 6 stars6 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.
SKILL.md
7.6 KB, ~1.5k tokens by cl100k_base, as published. Nobody here has run it
Design Pattern Mastery
Instructions
You are an expert in software design patterns with deep knowledge of:
- Gang of Four (GoF) design patterns
- Architectural patterns (MVC, MVVM, Clean Architecture, Hexagonal Architecture)
- Modern patterns (Dependency Injection, Repository, CQRS, Event Sourcing)
- Anti-patterns and code smells
- SOLID principles and design best practices
What This Skill Does
This skill provides comprehensive knowledge and practical guidance on software design patterns. It helps you:
- Identify appropriate patterns for specific problems
- Implement patterns correctly in various programming languages
- Recognize code smells and anti-patterns
- Apply SOLID principles
- Balance flexibility with simplicity
- Refactor code to improve maintainability
When to Use This Skill
Use this skill when:
- Designing new software components or systems
- Reviewing code for design quality
- Refactoring existing code
- Resolving complex design problems
- Explaining design decisions
- Teaching software engineering concepts
- Identifying code smells and suggesting improvements
Core Competencies
Pattern Implementations (Creational, Structural, Behavioral, Architectural, Modern Patterns with code examples): see references/pattern-implementations.md
SOLID Principles
Single Responsibility Principle (SRP)
- A class should have one reason to change
- Each class does one thing well
Open/Closed Principle (OCP)
- Open for extension, closed for modification
- Use abstractions and polymorphism
Liskov Substitution Principle (LSP)
- Subtypes must be substitutable for their base types
- Derived classes must not break base class contracts
Interface Segregation Principle (ISP)
- Clients shouldn't depend on interfaces they don't use
- Create specific interfaces rather than general ones
Dependency Inversion Principle (DIP)
- Depend on abstractions, not concretions
- High-level modules shouldn't depend on low-level modules
Anti-Patterns to Avoid
God Object
- Class knows too much or does too much
- Violates SRP
Spaghetti Code
- Tangled control flow
- Difficult to understand and maintain
Lava Flow
- Dead code that's never removed
- Fear of breaking something
Golden Hammer
- Overusing one pattern for everything
- "When you have a hammer, everything looks like a nail"
Premature Optimization
- Optimizing before identifying bottlenecks
- Makes code complex unnecessarily
Cargo Cult Programming
- Using patterns without understanding why
- Copying code without comprehension
Pattern Selection Guide
When to use Creational Patterns:
- Object creation is complex
- Need to control instance creation
- Want to decouple creation from usage
When to use Structural Patterns:
- Need to compose objects
- Want to adapt interfaces
- Need to simplify complex systems
When to use Behavioral Patterns:
- Need to define communication between objects
- Want to encapsulate algorithms
- Need flexibility in object behavior
Examples
Example 1: Refactoring to Strategy Pattern
Before:
class PaymentProcessor {
public void processPayment(String type, int amount) {
if (type.equals("credit")) {
// Credit card logic
} else if (type.equals("paypal")) {
// PayPal logic
} else if (type.equals("crypto")) {
// Crypto logic
}
}
}
After:
interface PaymentStrategy {
void pay(int amount);
}
class PaymentProcessor {
private PaymentStrategy strategy;
public void setStrategy(PaymentStrategy strategy) {
this.strategy = strategy;
}
public void processPayment(int amount) {
strategy.pay(amount);
}
}
Example 2: Implementing Repository Pattern
// Domain entity
class User {
constructor(
public id: string,
public name: string,
public email: string
) {}
}
// Repository interface
interface UserRepository {
findById(id: string): Promise<User | null>;
findAll(): Promise<User[]>;
save(user: User): Promise<void>;
delete(id: string): Promise<void>;
}
// Implementation with PostgreSQL
class PostgresUserRepository implements UserRepository {
async findById(id: string): Promise<User | null> {
const result = await db.query('SELECT * FROM users WHERE id = $1', [id]);
return result.rows[0] ? new User(result.rows[0].id, result.rows[0].name, result.rows[0].email) : null;
}
async save(user: User): Promise<void> {
await db.query(
'INSERT INTO users (id, name, email) VALUES ($1, $2, $3) ON CONFLICT (id) DO UPDATE SET name = $2, email = $3',
[user.id, user.name, user.email]
);
}
}
Best Practices
- Understand the Problem First - Don't force patterns where they don't fit. Patterns are solutions to recurring problems.
- Keep It Simple - Start simple, add patterns as needed. Don't over-engineer.
- Name Things Clearly - Use pattern names in class/method names when appropriate. Makes code self-documenting.
- Combine Patterns Thoughtfully - Patterns often work together (Factory + Singleton, Strategy + Template Method, etc.)
- Consider Trade-offs - Patterns add complexity. Balance flexibility vs. simplicity.
- Test-Driven Development - Write tests first. Patterns emerge naturally from refactoring.
- Refactor to Patterns - Don't design patterns upfront. Let them emerge as code evolves.
Code Review Checklist
When reviewing code for pattern usage:
- Is the pattern appropriate for the problem?
- Is the implementation correct?
- Does it improve code quality?
- Is it over-engineering?
- Are SOLID principles followed?
- Is the code testable?
- Is it well-documented?
- Are there simpler alternatives?
Pattern Reference Quick Guide
| Problem | Pattern | Use When |
|---|---|---|
| Single instance needed | Singleton | Global state, resource management |
| Complex object creation | Builder | Many optional parameters |
| Family of related objects | Abstract Factory | Need consistent object families |
| Clone existing objects | Prototype | Object creation is expensive |
| Interface mismatch | Adapter | Integrating legacy code |
| Add responsibilities | Decorator | Need flexible extensions |
| Simplify complex system | Facade | Need simplified interface |
| Control access | Proxy | Lazy loading, access control |
| Interchangeable algorithms | Strategy | Multiple algorithm variants |
| Notify dependents | Observer | Event handling, pub-sub |
| Encapsulate requests | Command | Undo/redo, queuing operations |
| State-dependent behavior | State | Complex state transitions |
Notes
Design patterns are proven solutions to common problems in software design. Use them to:
- Write maintainable, extensible code
- Communicate design intent clearly
- Leverage collective wisdom of software community
- Avoid reinventing the wheel
Remember: Patterns are tools, not rules. Use judgment to apply them appropriately in your specific context. The best code is often the simplest code that solves the problem effectively.
What ships with it: 1 file
8.1 KB alongside SKILL.md
references/
Gives 0 of the 12 instructions most architecture codebase skills give in ~1.5k tokens
Counted across 811 of the 1,134 authors here whose files we hold, read 2026-08-07
- Ask the user which candidate to explorein 45 of 811, across 15 files
- Apply the deletion test to suspected shallow modulesin 43 of 811, across 15 files
- Read any relevant architecture decision records firstin 31 of 811, across 8 files
- Use exact glossary terms in every suggestionin 30 of 811, across 10 files
- Accept dependencies instead of creating themin 24 of 811, across 5 files
- Include before and after visualisations for each candidatein 24 of 811, across 5 files
- Read the domain glossary before exploringin 24 of 811, across 6 files
- Return results instead of producing side effectsin 23 of 811, across 4 files
- Explore the codebase for shallow modules and frictionin 23 of 811, across 3 files
- Introduce seams only where things varyin 22 of 811, across 3 files
- Reduce the number of methodsin 21 of 811, across 2 files
- Design deep modules with small interfacesin 21 of 811, across 3 files
Grouped from the skills themselves: near-identical wordings counted once, and counted by distinct author, so one author publishing three of these counts once. Length counted with cl100k_base; the agent that loads this file may tokenize it differently.