[] Java design patterns Design Patterns builder mode

table of Contents

First, why use the builder pattern

Second, the schema definition

Third, the model structure

Fourth, the advantages of model

Fifth, the mode shortcomings

Sixth, for the environment


First, why use the builder pattern

Builder and its mode can be set member mounted separate process, step by step, to create a complex object . The user need only specify a complex object type of the object can be obtained, without having to know the specific details of its internal structure.

Second, the schema definition

Builder mode (the Pattern Builder) : The structure of a complex object is built and it means isolated , so constructed the same process can create different representations .
The builder pattern is a step by step to create a complex object , it allows you to build their families only by specifying the type and content of complex objects, users do not need to know specific details of the construction. The builder pattern belong to the object creation schema. Depending on the Chinese translation of the builder pattern and may be known as a generator mode.

Third, the model structure

Builders mode includes the following roles:
Builder : abstract Builder
ConcreteBuilder : concrete builder
Director: director (the one hand, it isolates the customer and production process ; on the other hand it is responsible for controlling the generation process of the product )
Product : Product roles

Fourth, the advantages of model

In the builder mode, the client does not have to know the details of the internal composition of the product, the product itself and the process of creating the product decoupled so that the same creation process can create different product objects .
each specific builders are relatively independent, regardless of other specific builder, so it can easily replace specific builder or add new concrete builder, users use different specific builder can get a different product target .
can more finely control the product creation process. The step of creating the complex decomposition products in different ways, so that the creation of clearer and more easy to use program to control the creation process.
Add a new concrete builder without modifying the original class library code to facilitate the expansion class commander for abstract builder class programming system, in line with "the principle of opening and closing."

Fifth, the mode shortcomings

the builder pattern created products generally have more in common, which is part of similar, if the difference between a great product is not suitable to use the builder pattern,
Its use is subject to certain limitations .
If the internal changes in product complexity, may cause a lot of need to define concrete builder classes to implement this change, cause the system to become very large .

Sixth, for the environment

need to generate products and objects have complex internal structures , these products often contain more than one member objects attributes.
properties need to generate products interdependent objects, you need to specify the order of their generation .
Create a process to create objects independent of the object's class . In the builder pattern introduced in the director category, the commander creation process encapsulated in the class, rather than in the builders.
isolation create and use complex objects, and makes the same creation process can create different products
Published 31 original articles · won praise 6 · views 4128

Guess you like

Origin blog.csdn.net/zhenliangit0918/article/details/104303551