問題に対して適切なパターン(またはパターンを使用しないという選択)を選択するには、問題を深く理解し、パターンとそのトレードオフを知り、メリットと複雑さのバランスを取るために判断力を発揮する必要があります。目標はパターンを使用することではなく、問題をうまく解決することです。
問題からはじめる。パターンからではなく
✓ UNDERSTAND THE PROBLEM first → what's the actual issue? (don't start by picking a pattern)
✓ Identify what you NEED → flexibility? decoupling? extensibility? simpler creation?
✓ Then ask: does a pattern address THIS problem well? (or is a simple solution better?)
→ problem-first, not pattern-first → avoid forcing patterns
パターンを問題にマッチさせる
Recognize which patterns fit which problems:
→ need ONE instance? → Singleton (or DI/module — consider alternatives)
→ decouple object creation? → Factory; complex construction? → Builder
→ swappable algorithms / eliminate conditionals? → Strategy
→ notify many of changes? → Observer; add behavior by wrapping? → Decorator
→ incompatible interfaces? → Adapter; simplify a subsystem? → Facade
→ undo/queue actions? → Command; control access? → Proxy
→ know the patterns' INTENT (the problem each solves) to recognize the fit
