Builder mode, which is the generator mode

Source: Internet
Author: User

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

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.