JavaScript design Pattern Classic Builder Pattern _javascript skills

Source: Internet
Author: User

The concept of builder model pattern

The builder pattern separates the construction of a complex object from its representation, allowing the same build process to create different representations. That is to say, if we use the builder model, then the user needs to specify the type that needs to be built to get them, and the process and details of the construction need not be known. The builder model is actually a conductor, a builder, and a client who uses the command to invoke the results of a specific builder's work.

The builder model is used primarily to "step through a complex object", where "step-by" is a stable algorithm, while the parts of complex objects often change.

Popular said: Is a white rich United States need to build a villa, and then directly to find a contractor, the contractor to find workers to build the villa. This one Bai Fumi not directly to a worker's to find. and the contractor know Bai Fumi needs, know where to find workers, workers can work, the middle save Bai Fumi and the cost of communication between workers, Bai Fumi also do not need to know how to build concrete house, finally can get the room.

Builder Pattern Structure diagram

Ii. role and considerations of the builder model

Mode function:

1. step-by-Step to create a complex object

2. Decoupling encapsulation process and concrete creation component

3. No need to care about how components are assembled

Precautions:

1. Must be a stable algorithm to support

2. Processing technology is exposed--Bai Fumi don't care how to build a house, but you can always go to see how the house is built.

Third, the builder pattern code and the actual combat summary

<! DOCTYPE html>  

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.