design-patternslisted
Install: claude install-skill tstapler/dotfiles
# Design Patterns
Apply patterns from two authoritative sources:
- **GoF**: *Design Patterns* — Gamma, Helm, Johnson, Vlissides
- **PoEAA**: *Patterns of Enterprise Application Architecture* — Martin Fowler
**Key principle**: patterns describe solutions to recurring problems — use them when the problem recurs, not to demonstrate pattern knowledge. In Go, first-class functions and interfaces make several GoF patterns unnecessary or simpler than in OOP languages.
---
> For encoding pattern invariants into the type system (Value Objects, sum types, smart constructors), apply the `type-driven-design` skill.
## GoF Creational Patterns
### Factory Method / Abstract Factory
**Problem**: Create objects without hardcoding concrete types; decouple creation from use.
```go
func NewReader(format string) Reader {
switch format {
case "json": return &JSONReader{}
case "xml": return &XMLReader{}
default: return &TextReader{}
}
}
```
- **Use when**: multiple concrete types implement the same interface; creation logic varies by context
- **Avoid when**: only one concrete type exists (just use a direct constructor)
- **Go note**: return interfaces, not concrete types; constructor functions are more idiomatic than factory objects
### Builder / Functional Options
**Problem**: Construct complex objects step-by-step, managing many optional parameters cleanly.
```go
// Idiomatic Go: functional options
type Option func(*Server)
func WithTimeout(d time.Duration) Optio