Creation mode - the builder pattern

Video link: https: //member.bilibili.com/v2#/upload-manager/article (review)

1. Definition of pattern are built

In software engineering, design patterns are created schema object creation process, trying to create an object using the appropriate way according to the actual situation. The basic object creation may cause problems on the way of design, or increase the complexity of the design. Create a schema to solve the problem by creating a control object in some way.
Creational pattern consists of two dominant ideology. One particular type of system used to encapsulate, two specific examples of these are hidden class is created and the binding manner.
Create a schema object creation schema is divided into classes and create a schema. Create a schema object creation process object, create a class to create a schema processing class. In detail, the object schema to create the delayed part of the object to another object created, and the created schema class it will defer the creation of objects into subclasses.
Creation mode can solve the problem:

(1) facilitate the user to create complex objects (not need to know the implementation process)

(2) encapsulation and reusability of code (the build process and details of objects encapsulation and multiplexing)

When is like making cars and buy cars, factories (as a role model builder) which is responsible for making cars, were in the assembly process and details of the factory again. Car buyers (as the user's role) you just need to tell the model you need and then you can buy directly, and you do not need to know how the car is assembled.

2. Role model builder

Builder (Builder): Specifies the abstract interface for creating the various components of a product object.
Specific builder (ConcreteBuilder): Builder interface to implement construction and assembly of the various components of the product, defined and clearly expressed that it creates and provides an interface to retrieve the product.
Director (Director): command and construct an object using the Builder interface.
Product (Product): represent complex objects are constructed. ConcreteBuilder create an internal representation of the product and define its assembly process, comprising component parts defined class, including these components are assembled into the final product interface.

The relationship between these roles are:

  • Director (Director) and direct clients (Client) conduct needs to communicate;
  • The commander customers to create products for the construction division after the communication needs of the various components of the request (Builder);
  • The construction of each component requests delegated to a specific builder (ConcreteBuilder);
  • Each specific builder is responsible for building product components;
  • The final construct into specific product (Product).

Figure:
 

3. The advantages and disadvantages of model builder

advantage:

(1) using the builder pattern enables the client does not have to know the details of the internal composition of the product.

(2) between the concrete builder classes are independent of each other, which is conducive to expansion of the system.

(3) specific builders are independent, so you can gradually refine the process of construction and would not have any impact on other modules.

Disadvantages:

(1) the builder pattern created products generally have more in common, which similar components; if significant differences between products, is not suitable if the builder pattern, its use is subject to certain limitations.

(2) 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.




Guess you like

Origin www.cnblogs.com/jyqdaisy/p/12589206.html