Explain:
Separating the construction of a complex object from its representation allows the same build process to create unused representations.
Structure diagram:
Advantages:
The internal representation of a product can be separated from the production process, allowing a construction process to produce product objects with different internal representations.
Separating the construction code from the presentation code, as the builder hides how the product is assembled, so if you need to change the inside of a product, you just need to define a concrete builder.
If the builder mode is used, the user can get them only by specifying the type they need to build, and the concrete construction process and details do not need to be known.
Usage Environment:
It is primarily used to create complex objects in which the build order of the internal builds is usually stable, but the construction of the objects within the object often faces complex changes.
When creating complex objects, the algorithm should be independent of the part of the object and the mode in which they are assembled.
Usage Recommendations:
For the refinement of the builder class, a tradeoff is needed. If these details are to be constructed for each specific subclass, then it should be added. Conversely, it is not necessary.
In fact, the construction pattern is the gradual construction of the product, so the builders of the builder class in the building methods must be enough to be common to the various types of concrete builders to construct.
Example:
Abstract Builder class: Built parts that prevent any subclasses from forgetting.
Conductor class: Controls the build process. Used to isolate the user from the construction process.
Client:
Extended:
1. Dependency reversal principle: abstractions should not be dependent on details, and details should be dependent on abstraction.
Builder mode, which is the generator mode