I. Builder (BUILDER) model
The builder model separates the internal representation of a product from the product generation process, enabling a build process to generate a product object with a different internal representation.
Construction of Object Nature
In some cases, an object will have some important properties that cannot be used as a complete product until they have the proper value. For example, an e-mail message has a sender's address, a recipient's address, a subject, content, an appendix, and so on, which cannot be sent until the minimum recipient address has been assigned.
In some cases, it makes sense that some of the properties of an object must be assigned in a certain order. Another property cannot be assigned until a property is assigned a value. These circumstances allow the construction of nature itself to involve complex business logic.
At this time, this object is equivalent to a product to be built, and the object of these properties is equivalent to the product parts, the process of building a product is the process of assembling parts. Because the process of assembling parts is complex, the combination process of these "parts" is often "externalized" to an object called a builder, which is returned to the client by a product object in which all parts have been built.
The naming considerations
The reason for using "builder" instead of "generator" is that it is more appropriate to "build" and "create" or "build" than to produce a product from a part.
Second, the structure of the builder model:
Builder (Builder) role: An abstract interface is given to standardize the construction of each component of a Product object. Generally speaking, this interface is independent of the business logic of the application. The direct creation of product objects in a pattern is the specific builder (concretebuilder) role. The concrete builder class must implement the method required by this interface: one is the construction method and the other is the result return method.
The specific builder (concrete Builder) Role: This role is a tightly related class of applications that create product instances under application calls. The main tasks that the role accomplishes include:
Implement the interface provided by the builder role and step through the process of creating a product instance.
Provide an example of the product after the construction process is completed.
Mentor (Director) Role: The class that holds the role calls the concrete builder role to create the Product object. Directors do not have specific knowledge of the product category, the specific knowledge of the actual product class is the specific builder object.
Product role: A product is a complex object in construction.
The Mentor role is the client's role in dealing with. The Director role divides the client's request to create a product into a build request for each part, and then delegates those requests to the specific builder role. The concrete builder role is to do the concrete construction work, but is not known by the client.