The builder for iOS design mode

Source: Internet
Author: User

The builder for iOS design mode1.definition of generator pattern

(1): Separates the component of a complex object from its representation, allowing the same build process to create different representations

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

2: Advantages of using generators

There are many different ways of building some objects, and assuming that the logic is included in a single method of building the classes of these objects, the logic will be very complex (for example: a large absconded if-else for various building requirements), and the process will become manageable, assuming the relationship between the customer-mentor-generator is decomposed.


3. UML for generator mode


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

ConcreteBuilder : The implementation class for the detailed generator

Product: The complex object that is built by the generator. Includes multiple parts

Director: The mentor is also known as the guide person. Used primarily to use the Builder interface. A unified interface has been created to create the Product object



4. Comparison of generator mode and abstract Factory mode


Formally speaking, through the role of merging. The transformation of the method function, the abstract factory can be consistent with the form of the generator pattern (for example, the abstract factory only processes a product family, the factory method handles the same product). But notice, it's just formal. As a matter of fact. There are essential differences between the abstract factory and the generator pattern:


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 family products (the only bound is that we all belong to one family).


2. The generator pattern is constructed in order to construct the same product, so there must be mentors to coordinate the work. There is a certain business relation between the construction methods, and the construction method of the abstract factory is to build its own product object independently. So they don't have a certain connection.

In generator mode, the client does not call the build product section directly to get the product finally. The client in the abstract factory gets 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 such a method to live unpredictable results. These methods in the abstract factory must be in public form. Otherwise the customer cannot call to obtain the product result;


4. The Role builder for the generator mode. Products and mentors, and the roles of abstract factories are factories and products.

Regardless of how roles and functions are transformed, the included business logic roles should exist, which is the business nature of the two models.




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.