JavaScript design mode: Classic builder mode and javascript Design Mode

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.