Builderパターンは複雑なオブジェクトを段階的に構築し、構築処理と表現を分離します。多くのパラメータまたはオプション部分を持つオブジェクトに特に有効で、煩雑なコンストラクタの代わりに、読みやすく柔軟なオブジェクト構築を実現します。
Builderが解決する問題
Objects with MANY parameters (especially optional ones) lead to problems:
✗ huge constructors: new Pizza('large', true, false, true, 'thin', false, ...) →
unreadable (which boolean is what?); hard to use; error-prone
✗ many constructor overloads (telescoping constructors) → messy
→ Builder provides a clean, readable, step-by-step way to construct such objects.
Builderの動作原理
pizza = ()
.()
.()
.()
.()
.();
