The builder for iOS design mode

Source: Internet
Author: User

The builder for iOS design mode 1. definition of generator pattern

(1): Separates the component of a complex object from its representation so that the same build process can create different representations

(2): Generator mode includes a Director (mentor) and a builder (builder) In addition to the client. The client presents the requirements to the Director (Director) to the Bulider (generator) Provide information to build a particular product. Bulider produces products based on specific information and returns them to customers.

2: Benefits of using generators

There are many different ways to build some objects, and if the logic is contained in a single method of building the classes of these objects, the logic is complex (for example: a large absconded if-else for various build requirements), and if the relationship between the customer-mentor-generator is decomposed, the process becomes manageable.


3. UML for generator mode


Builder : Generator interface, defining actions to create a Product 's individual parts

ConcreteBuilder : The implementation class for the specific generator

Product: A complex object that is built by the generator, containing multiple parts

Director: The mentor is also called the Guide, which is used primarily to create a Product object using the Builder interface, which has a unified interface



4. Comparison of the generator pattern and the abstract factory model


Formally speaking, through the role of merging, the transformation of the function of the method, the abstract factory can be consistent with the generator pattern (such as the abstract factory only deal with a product family, factory methods are processed the same product). But note that this is only formal, in fact, the abstract factory and generator patterns are essentially different:


1, the generator mode is to construct a complex product, and the purchase of the product follows certain rules (the same process), and the abstract factory is to create a family of products (series), There is no logical connection between the structure of kindred products (the only necessary connection is that we all belong to one family).


2, the construction method of the generator pattern is to construct the same product, therefore must have the guidance to coordinate the work, the construction method has the inevitable business relation, but the abstract factory constructs the method to construct own product object independently, therefore they do not have the inevitable connection. In generator mode, the client does not directly invoke the method of building the product section to obtain the final product, while the client in the abstract factory obtains different products by invoking different factory methods.


3. in the generator pattern, the methods used to construct different parts of the product are generally implemented as Protected forms to prevent the client from having to invoke this method to live unpredictable results, and these methods in the abstract factory must be public form. Otherwise the customer cannot call to obtain the product result;


4. The role of the generator pattern has generators, products and mentors, while the role of the abstract factory has factories and products. Regardless of how roles and functions are transformed, the business logic roles involved should exist, which is the business nature of the two models.




Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

The builder for iOS design mode

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.