JavaScript design mode: Classic builder mode and javascript Design Mode
1. Concepts of builder Mode
The builder mode separates the construction of a complex object from its representation, so that different representations can be created for the same build process. That is to say, if we use the builder mode, users need to specify the types to be built to get them, and the specific construction process and details do not need to be known. The builder mode is actually a conductor, a builder, and a customer who uses the conductor to call a specific builder to produce results.
The builder mode is mainly used to "build a complex object by step", where "Step by Step" is a stable algorithm, while all parts of a complex object change frequently.
In layman's terms, Bai fumei needs to build a villa and then directly find the contractor's head. Then, the contractor needs to find a worker to build the villa. In this case, Bai fumei does not need to find one worker. The contractor knows the needs of Bai fumei and where to find the workers. The workers can work, saving the communication cost between Bai fumei and the workers, bai fumei does not need to know how to build the house. He can finally get the house.
Builder mode structure
Ii. Functions and precautions of builder Mode
Role of the Mode:
1. Create a complex object step by step
2. Decoupling the encapsulation process and creating Components
3. No need to care about how components are assembled
Note:
1. A stable algorithm must be supported.
2. The processing technology is exposed-bai fumei does not have to worry about how to build a house, but he can check how the house is built at any time.
Iii. Builder mode code and practice summary
<! DOCTYPE html>
Articles you may be interested in:
- Introduction to the builder mode of JavaScript Design Patterns
- A deep understanding of the JavaScript series (27): a detailed explanation of the builder mode of the Design Mode