Design Mode learning Summary (4) builder Mode

Source: Internet
Author: User

This series mainly records what the design pattern intends to be, what issues it wants to solve, and when it can be used; how it solves it, master its structure diagram, remember its key code; be able to think of at least two of its application instances, one in life and one in software; What are the advantages and disadvantages of this model, and what use scenarios are there, what should I pay attention to when using it.

4. Builder Mode

Intention: Separate a complex build from its representation so that the same build process can create different representations.

Major solution: In software systems, there are sometimes "a complex object", which is usually composed of sub-objects in various parts using certain algorithms. due to changes in requirements, the various parts of this complex object often face drastic changes, but the algorithms that combine them are relatively stable.

When to use: some basic components will not change, but the combination will often change

How to solve the problem: Changing and leaving without change


Key code: builder: Create and provide instances, Director: Manage the dependencies of the created instances

Application Example: 1. Go to KFC, hamburger, cola, french fries, fried chicken wings and so on, and its combination is constantly changing, generate the so-called "package" 2. StringBuilder in JAVA

Advantages: 1 The builder is independent and easy to expand 2. Easy to control detailed risks

Disadvantages: 1. products must have something in common and the scope is limited. 2. If internal changes are complicated, there will be many construction classes.

Use Cases: 1. the object to be generated has a complex internal structure 2. The internal attributes of the object to be generated are dependent on each other.

Note: The difference from the factory mode is that the builder mode pays more attention to the order of assembly with parts.

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: 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.