[Design mode] builder Mode

Source: Internet
Author: User

Introduction

Separates the construction of a complex object from its representation so that different representations can be created during the same construction process.

Builder mode English: Builder

Details

The builder mode has the following advantages: users only need to specify the types to be built to obtain them, but they do not need to know the specific construction process and details.

The builder pattern structure diagram has recently become more and more fond of UML class diagrams, which are clear and clear.

When to use the builder mode: it is mainly used to create complex objects. The building sequence between the internal components of these objects is usually stable, but the building of internal objects of objects is usually subject to complex changes. The construction code in the builder mode is separated from the representation code. Because the builder hides how the product is assembled, if you need to change the internal representation of a product, you only need to define a specific builder.

Builder: the builder's abstract interface provides classes. For example, to build an object, you must call buildparta () and buildpartb ().

Concretebuilder: The specific builder implements buildparta () and buildpartb (), and provides getresult () for obtaining the product's friends ().

Director: Command builder to complete the specific creation process

Void construct (builder * bb)

{

Bb-> buildparta ();

Bb-> buildpartb ();

}

Director ensures that the object is completely created. concretebuilder provides the specific creation method.

Product: the final product of the final product and builder model. The interfaces provided by builder are used to build the final product.

Xiaoji

It seems that this method is not practical. It is only used to build objects in a unified manner. It seems that it increases the complexity and does not receive the role of unified abstraction, is it just to ensure that the product is successfully built?

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.