design-patternslisted
Install: claude install-skill andr-ca/agentharness
# Design Patterns (GoF Reference)
Patterns solve recurring design problems. **Don't introduce a pattern to a problem that doesn't exist yet.**
---
## Creational — Object Creation
### Factory Method
Create objects without knowing the concrete class.
```python
class NotificationFactory:
@staticmethod
def create(channel: str) -> Notification:
match channel:
case "email": return EmailNotification()
case "sms": return SmsNotification()
case _: raise ValueError(f"Unknown channel: {channel}")
```
**Use when:** the exact type to create is determined at runtime, or varies by environment.
### Builder
Construct complex objects step by step, separating construction from representation.
```typescript
const email = new EmailBuilder()
.to("alice@example.com")
.subject("Hello")
.body("World")
.build();
```
**Use when:** constructors would have 4+ parameters, especially optional ones.
---
## Behavioral — Object Communication
### Strategy
Define a family of algorithms and make them interchangeable at runtime.
```python
class Sorter:
def __init__(self, strategy: SortStrategy) -> None:
self._strategy = strategy
def sort(self, data: list) -> list:
return self._strategy.sort(data)
```
**Use when:** you have multiple ways to do something and want to switch them. Replace `if/elif` chains.
### Observer (Event / Pub-Sub)
One object notifies many dependents without knowing who they are.
```typ