Builder Design Pattern �(Creational)
Thanh Le – Software Architect / Technical Consultant
Complexity: 2,5/3
Popularity: 3/3
Intent
��
Image source: internet
Motivation
Imagine a complex object that requires laborious, step-by-step initialization of many fields and nested objects. Such initialization code is usually buried inside a monstrous constructor with lots of parameters. Or even worse: scattered all over the client code.
�
Image source: internet
You might make the program too complex by creating a subclass for every possible configuration of an object.
Solution
��
Image source: internet
Different builders execute the same task in various ways.
The Builder pattern lets you construct complex objects step by step. The Builder doesn’t allow other objects to access the product while it’s being built.
�
Solution (cont)
Image source: internet
The director knows which building steps to execute to get a working product.
Structure
Image source: internet
Pros/Cons
Practice
https://github.com/thanhle0212/23GoF-Design-Patterns-CSharp