The analysis and implementation of design pattern (c + +) Three-builder mode

Source: Internet
Author: User

Role:

The construction of a complex object is separated from its representation, allowing the same build process to create different representations.

UML Structure diagram:

Applies to the following situations:

1 The algorithms for creating complex objects should be independent of the components of the object and the way they are assembled.

2 when the construction process must allow the constructed object to have a different representation.

Abstract base class:

1 Builder: This base class is an abstraction of all the process of creating objects, providing interface functions to build different components

Interface:

1) BUILDER::BUILDPARTA,BUILDER::BUILDPARTB: It is the construction function interface of the different parts of an object, the Builder derived class to implement concretely.

Another function to note is the Director::construct function, which completes the construction of the object by calling the two interface functions above--that is, the process of assembling the different parts is consistent (the same construct function of the call), But different builds have different representations (depending on the actual type of builder to determine how to build, that is, polymorphism)

Analytical:

The builder model is based on a situation where: an object may have different components, and the different objects in these sections will have different representations, but the way in which the parts are assembled is consistent. For example, a bicycle is made up of wheel seats and so on (a different part of an object), Different brands are produced differently (different build styles). Although different brands build bicycles differently, the process is the same (oh, have you ever seen a wheel in a car seat?).

In other words, the director::construct function is fixed by the assembly of the various components, and specifically how the components of the assembly by the builder derived class implementation.

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.