デザインパターンとは、よくあるソフトウェア設計上の問題に対する再利用可能で実証済みの解決策です。繰り返し発生する課題を解決するためにコードをどう構造化するかを示す、一般的なテンプレートです。共通の語彙と検証済みのアプローチを提供し、より良く、より保守しやすいコードを書く助けになります。
デザインパターンとは何か
DESIGN PATTERNS = proven, reusable solutions to RECURRING design problems:
→ not code to copy, but TEMPLATES/approaches for structuring code
→ distilled from experience (best practices for common situations)
→ e.g. "how do I ensure only one instance of a class?" → Singleton pattern
→ describe the PROBLEM, the SOLUTION structure, and the trade-offs
古典的な分類(Gang of Four)
CREATIONAL → how OBJECTS are created (Singleton, Factory, Builder, Prototype)
STRUCTURAL → how objects/classes are COMPOSED (Adapter, Decorator, Facade, Proxy, Composite)
BEHAVIORAL → how objects INTERACT/communicate (Observer, Strategy, Command, Iterator, State)
→ the famous "GoF" (Gang of Four) patterns; many others exist too
