home / skills / dasien / claudemultiagenttemplate / design-patterns

This skill helps you apply design patterns like factory, observer, and strategy to design flexible, maintainable Python code.

npx playbooks add skill dasien/claudemultiagenttemplate --skill design-patterns

Review the files below or copy the command above to add this skill to your agents.

Files (1)
SKILL.md
1.9 KB
---
name: "Design Pattern Application"
description: "Apply Gang of Four and architectural patterns appropriately to solve common software design problems"
category: "architecture"
required_tools: ["Read", "Write"]
---

## Purpose
Recognize when to apply established design patterns to create flexible, maintainable, and reusable code structures.

## When to Use
- Designing class structures
- Solving recurring design problems
- Refactoring complex code
- Planning extensible architectures

## Key Capabilities
1. **Pattern Recognition** - Identify when patterns apply
2. **Pattern Implementation** - Correctly implement chosen patterns
3. **Trade-off Analysis** - Understand pattern costs and benefits

## Common Patterns
- **Creational**: Factory, Builder, Singleton
- **Structural**: Adapter, Decorator, Facade
- **Behavioral**: Observer, Strategy, Command

## Example - Strategy Pattern
```python
# Problem: Multiple payment methods with different processing logic

class PaymentStrategy:
    def process(self, amount): pass

class CreditCardPayment(PaymentStrategy):
    def process(self, amount):
        # Credit card processing logic
        print(f"Processing ${amount} via credit card")

class PayPalPayment(PaymentStrategy):
    def process(self, amount):
        # PayPal processing logic
        print(f"Processing ${amount} via PayPal")

class Order:
    def __init__(self, payment_strategy: PaymentStrategy):
        self.payment = payment_strategy
    
    def checkout(self, amount):
        self.payment.process(amount)

# Usage
order1 = Order(CreditCardPayment())
order1.checkout(100)

order2 = Order(PayPalPayment())
order2.checkout(50)
```

## Best Practices
- ✅ Use patterns to solve actual problems, not for their own sake
- ✅ Understand the problem before applying a pattern
- ✅ Keep it simple - don't over-engineer
- ❌ Avoid: Using patterns you don't fully understand
- ❌ Avoid: Forcing patterns where they don't fit

---

Overview

This skill applies Gang of Four and architectural design patterns to solve common software design problems in multi-agent Python systems. It helps choose, implement, and evaluate patterns that improve flexibility, maintainability, and reuse. The guidance focuses on pragmatic pattern use in agent templates, task queues, and automated workflows.

How this skill works

The skill inspects code-level responsibilities and interactions to recognize candidate patterns (creational, structural, behavioral) and recommends concrete implementations. It provides short examples, trade-off analysis, and refactoring steps tailored to multi-agent templates and task management flows. It also suggests when a simpler approach is preferable to avoid over-engineering.

When to use it

  • Designing class hierarchies or object creation in agent modules
  • Standardizing communication or integration between specialized agents
  • Refactoring a messy codebase to improve extensibility and testability
  • Implementing pluggable strategies for scheduling, routing, or payment processing
  • Introducing clear separation of concerns in task queue management

Best practices

  • Apply patterns to real, recurring problems rather than for style or completeness
  • Start with a simple implementation and evolve to a fuller pattern as needs grow
  • Document the reason and expected benefits when introducing a pattern
  • Prefer composition over inheritance when aiming for flexibility
  • Analyze trade-offs: complexity, performance, and testability before committing

Example use cases

  • Use Strategy to swap scheduling or routing algorithms across agents without changing agent code
  • Apply Factory or Builder for constructing complex agent configurations and pipelines
  • Use Adapter to wrap legacy task queue clients to match a new scheduler interface
  • Apply Observer for event-driven notifications between agents and monitoring components
  • Use Facade to present a simple API over a set of agent orchestration utilities

FAQ

How do I choose between composition and inheritance?

Prefer composition when behavior should be changeable at runtime or when you want looser coupling; use inheritance when there is a clear is-a relationship and stable abstractions.

When is Singleton acceptable?

Use Singleton sparingly for truly global, shared resources (logging, config) but prefer dependency injection to keep code testable and reduce hidden state.

Can patterns increase complexity?

Yes. Patterns trade simplicity for structure. Always weigh added abstraction against maintainability gains and prefer minimal necessary structure.