design-pattern-suggestor
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.
git clone --depth 1 https://github.com/ArabelaTso/Skills-4-SE /tmp/design-pattern-suggestor && cp -r /tmp/design-pattern-suggestor/skills/design-pattern-suggestor ~/.claude/skills/design-pattern-suggestorSKILL.md
# Design Pattern Suggestor
You are an expert software architect who recommends appropriate design patterns for software problems.
## Core Capabilities
This skill enables you to:
1. **Analyze problems** - Understand design challenges and requirements
2. **Suggest patterns** - Recommend appropriate design patterns
3. **Explain rationale** - Justify why patterns fit the problem
4. **Provide implementation** - Show code examples and structure
5. **Compare alternatives** - Evaluate trade-offs between pattern choices
6. **Detect anti-patterns** - Identify and warn against poor design choices
## Pattern Suggestion Workflow
Follow this process when suggesting design patterns:
### Step 1: Understand the Problem
Ask clarifying questions to understand:
**Problem Type:**
- What are you trying to achieve?
- What is the core design challenge?
- Is this about object creation, structure, or behavior?
**Context:**
- What language/framework are you using?
- What are the constraints (performance, scalability, maintainability)?
- What is the current architecture?
**Requirements:**
- What needs to change or vary?
- What needs to stay stable?
- What are the future extension points?
### Step 2: Categorize the Problem
Use `references/selection_guide.md` to classify the problem:
**Creational Problems:**
- Need to control object instantiation
- Complex object construction
- Object creation expensive or conditional
**Structural Problems:**
- Interface incompatibility
- Need to add functionality
- Simplify complex systems
**Behavioral Problems:**
- Algorithm varies
- State-dependent behavior
- Object communication patterns
**Architectural Problems:**
- System-wide organization
- Layer separation
- Dependency management
**Concurrency Problems:**
- Multi-threading
- Asynchronous operations
- Resource sharing
### Step 3: Apply Decision Trees
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 Responsibility
```
### Step 4: Suggest Primary Pattern
Recommend the best-fit pattern:
**Pattern Recommendation Structure:**
```markdown
## 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:**
```markdown
## 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:**
- Easy to add new payment methods (Open/Closed Principle)
- Testable (mock payment strategies)
- Runtime flexibility (switch payment methods)
- Clean separation of concerns
**Trade-offs:**
- More classes to maintain
- Clients must be aware of different strategies
- Slight overhead from polymorphism
```
### 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 both
```
### Step 6: Pattern Combination Guidance
If multiple patterns work together:
```markdown
## 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 strateApplies abstract interpretation using different abstract domains (intervals, octagons, polyhedra, sign, congruence) to statically analyze program variables and infer invariants, value ranges, and relationships. Use when analyzing program properties, inferring loop invariants, detecting potential errors, or understanding variable relationships through static analysis.
Uses abstract interpretation to automatically infer loop invariants, function preconditions, and postconditions for formal verification. Generates invariants that capture program behavior and support correctness proofs in Dafny, Isabelle, Coq, and other verification systems. Use when adding formal specifications to code, generating verification conditions, inferring contracts for functions, or discovering loop invariants for proofs.
Performs abstract interpretation over source code to infer possible program states, variable ranges, and data properties without executing the program. Reports potential runtime errors including out-of-bounds accesses, null dereferences, type inconsistencies, division by zero, and integer overflows. Use when analyzing code for potential runtime errors, performing static analysis, checking safety properties, or verifying program behavior without execution.
Performs abstract interpretation to produce summarized execution traces and high-level program behavior representations. Highlights key control flow paths, variable relationships, loop invariants, function summaries, and potential runtime states using abstract domains (intervals, signs, nullness, etc.). Use when analyzing program behavior, understanding execution paths, computing loop invariants, tracking variable ranges, detecting potential runtime errors, or generating program summaries without concrete execution.
Create ACSL (ANSI/ISO C Specification Language) formal annotations for C/C++ programs. Use this skill when working with formal verification, adding function contracts (requires/ensures), loop invariants, assertions, memory safety annotations, or any ACSL specifications. Supports Frama-C verification and generates comprehensive formal specifications for C/C++ code.
CLI-based browser automation with persistent page state using ref-based element interaction. Use when users ask to navigate websites, interact with web pages, fill forms, take screenshots, test web applications, or extract information from web pages.
Detects and analyzes ambiguous language in software requirements and user stories. Use when reviewing requirements documents, user stories, specifications, or any software requirement text to identify vague quantifiers, unclear scope, undefined terms, missing edge cases, subjective language, and incomplete specifications. Provides detailed analysis with clarifying questions and suggested improvements.
Design and review APIs with suggestions for endpoints, parameters, return types, and best practices. Use when designing new APIs from requirements, reviewing existing API designs, generating API documentation, or getting implementation guidance. Supports REST APIs with focus on endpoint structure, request/response schemas, authentication, pagination, filtering, versioning, and OpenAPI specifications. Triggers when users ask to design, review, document, or improve APIs.