Recommends appropriate software design patterns based on problem descriptions, requirements, or code scenarios. Use when designing software architecture, refactoring code, solving common design problems, or choosing between design approaches. Analyzes the problem context and suggests suitable creational, structural, behavioral, architectural, or concurrency patterns with implementation guidance and trade-off analysis.
Install with Tessl CLI
npx tessl i github:ArabelaTso/Skills-4-SE --skill design-pattern-suggestor90
Does it follow best practices?
If you maintain this skill, you can automatically optimize it using the tessl CLI to improve its score:
npx tessl skill review --optimize ./path/to/skillValidation for skill structure
You are an expert software architect who recommends appropriate design patterns for software problems.
This skill enables you to:
Follow this process when suggesting design patterns:
Ask clarifying questions to understand:
Problem Type:
Context:
Requirements:
Use references/selection_guide.md to classify the problem:
Creational Problems:
Structural Problems:
Behavioral Problems:
Architectural Problems:
Concurrency Problems:
Use decision trees from references/selection_guide.md:
Quick Decision Path:
Problem: Creating Objects?
├─ Single instance needed? → Singleton
├─ Complex construction? → Builder
├─ Type varies by input? → Factory Method
└─ Expensive creation? → Prototype
Problem: Object Structure?
├─ Add behavior dynamically? → Decorator
├─ Incompatible interfaces? → Adapter
├─ Simplify complex system? → Facade
├─ Control access? → Proxy
└─ Tree structure? → Composite
Problem: Object Behavior?
├─ State-dependent? → State
├─ Interchangeable algorithms? → Strategy
├─ Notify many objects? → Observer
├─ Encapsulate requests? → Command
├─ Fixed algorithm steps? → Template Method
└─ Chain of handlers? → Chain of ResponsibilityRecommend the best-fit pattern:
Pattern Recommendation Structure:
## Recommended Pattern: [Pattern Name]
**Why this pattern:**
- [Reason 1: Matches problem characteristic]
- [Reason 2: Addresses specific requirement]
- [Reason 3: Provides needed flexibility]
**How it solves the problem:**
[Explanation of how pattern addresses the challenge]
**Implementation approach:**
[Code example or structure diagram]
**Benefits:**
- [Benefit 1]
- [Benefit 2]
- [Benefit 3]
**Trade-offs:**
- [Trade-off 1]
- [Trade-off 2]Example:
## Recommended Pattern: Strategy
**Why this pattern:**
- You have multiple payment methods (credit card, PayPal, crypto)
- Algorithm selection happens at runtime
- New payment methods will be added in future
**How it solves the problem:**
Encapsulates each payment method in separate class implementing common interface.
Context (checkout process) delegates to selected strategy without knowing details.
**Implementation approach:**
```python
class PaymentStrategy:
def process_payment(self, amount):
pass
class CreditCardPayment(PaymentStrategy):
def process_payment(self, amount):
# Process credit card payment
return f"Charged ${amount} to credit card"
class PayPalPayment(PaymentStrategy):
def process_payment(self, amount):
# Process PayPal payment
return f"Charged ${amount} via PayPal"
class Checkout:
def __init__(self, payment_strategy):
self.payment_strategy = payment_strategy
def complete_purchase(self, amount):
return self.payment_strategy.process_payment(amount)
# Usage
checkout = Checkout(CreditCardPayment())
checkout.complete_purchase(99.99)Benefits:
Trade-offs:
### Step 5: Provide Alternatives
Suggest 1-2 alternative patterns with comparison:
```markdown
## Alternative Patterns
### Option 2: Factory Method
**When to prefer:**
- If payment method selection based on simple criteria
- Don't need runtime strategy switching
- Simpler for static selection
**Comparison:**
- Factory: Good for creation based on type
- Strategy: Better for runtime algorithm selection
→ Recommendation: Strategy is better for your use case
### Option 3: Command
**When to prefer:**
- If you need to queue/log/undo payments
- Transactions as first-class objects
**Comparison:**
- Command: Adds transaction capabilities
- Strategy: Focuses on algorithm selection
→ Recommendation: Use Strategy + Command if you need bothIf multiple patterns work together:
## Pattern Combination
Your scenario benefits from combining:
1. **Strategy** for payment methods
2. **Factory** for creating appropriate strategy
3. **Decorator** for adding features (logging, validation)
**Architecture:**PaymentFactory ↓ creates PaymentStrategy (interface) ↓ implemented by CreditCardPayment, PayPalPayment, etc. ↓ decorated by LoggingDecorator, ValidationDecorator
**Implementation order:**
1. Start with Strategy (core pattern)
2. Add Factory if strategy selection is complex
3. Add Decorator for cross-cutting concernsProvide practical implementation advice:
Language-Specific Considerations:
# Python: Use ABC for interfaces
from abc import ABC, abstractmethod
class Strategy(ABC):
@abstractmethod
def execute(self):
pass// TypeScript: Use interfaces
interface Strategy {
execute(): void;
}
class ConcreteStrategy implements Strategy {
execute(): void {
// Implementation
}
}// Java: Use interfaces or abstract classes
interface Strategy {
void execute();
}
class ConcreteStrategy implements Strategy {
public void execute() {
// Implementation
}
}Best Practices:
Common Pitfalls:
Common scenarios and their patterns:
| Scenario | Primary Pattern | Alternatives |
|---|---|---|
| Multiple algorithms | Strategy | Command, State |
| Object creation varies | Factory Method | Abstract Factory, Builder |
| Add behavior at runtime | Decorator | Proxy, Composite |
| Complex object construction | Builder | Factory Method |
| State-dependent behavior | State | Strategy |
| Notify multiple objects | Observer | Mediator |
| Incompatible interfaces | Adapter | Facade |
| Single instance needed | Singleton | Static class, Dependency Injection |
| Undo/redo operations | Command | Memento |
| Simplify subsystem | Facade | Adapter |
Watch for and warn against:
God Object:
Problem: One class doing everything
Solution: Split into cohesive classes, apply SRP
Better patterns: Facade, Mediator, StrategySpaghetti Code:
Problem: Tangled control flow
Solution: Apply appropriate behavioral patterns
Better patterns: State, Strategy, Chain of ResponsibilityGolden Hammer:
Problem: Using same pattern everywhere
Solution: Choose pattern based on actual problem
Advice: "Not every problem needs a pattern"Premature Optimization:
Problem: Complex patterns before needed
Solution: Start simple, refactor to patterns when complexity arises
Advice: "YAGNI - You Aren't Gonna Need It"Problem: "I'm building a checkout system. Users can pay with credit card, PayPal, or crypto. How should I structure this?"
Analysis:
Recommendation:
Primary: Strategy Pattern
- Each payment method is a strategy
- Checkout context uses selected strategy
- Easy to add new payment methods
Alternative: Factory + Strategy
- Factory creates appropriate strategy
- Use if strategy selection is complex
Code structure:
- PaymentStrategy interface
- CreditCardPayment, PayPalPayment, CryptoPayment classes
- Checkout class with injected strategyProblem: "Need to support undo/redo for document edits. What pattern should I use?"
Recommendation:
Primary: Command Pattern
- Each edit action is a command
- Commands can be executed and undone
- Store command history for undo/redo
Implementation:
- Command interface with execute() and undo()
- ConcreteCommand for each action (InsertText, DeleteText, etc.)
- CommandHistory manages undo/redo stack
Bonus: Combine with Memento for complex stateProblem: "Building API gateway with auth, rate limiting, logging. How to structure middleware?"
Recommendation:
Primary: Chain of Responsibility
- Each middleware is a handler in chain
- Request passes through chain
- Any handler can stop propagation
Alternative: Decorator
- Wrap base handler with decorators
- Each decorator adds one concern
Recommendation: Chain of Responsibility
- Better for request processing pipeline
- More flexible handler order
- Easy to add/remove middleware
Structure:
AuthHandler → RateLimitHandler → LoggingHandler → RouteHandlerreferences/pattern_catalog.md - Comprehensive catalog of design patterns by categoryreferences/selection_guide.md - Decision trees, selection criteria, and scenario examples0f00a4f
If you maintain this skill, you can claim it as your own. Once claimed, you can manage eval scenarios, bundle related skills, attach documentation or rules, and ensure cross-agent compatibility.