Video link: https: //member.bilibili.com/v2#/upload-manager/article (review)
1. Definition of pattern are built
(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.