Android Design Pattern series (12)-SDK source code generator pattern (builder pattern)

Source: Internet
Author: User
Tags define abstract

The builder mode separates the constructor and representation, and produces a corresponding object based on the customer's needs.
Originally, we implemented different specific concretebuilder Based on the builder interface to produce different objects.
However, the following example only contains one builder, so there is no interface builder or other concretebuilder.
However, the example I want to talk about today is too simple. I don't think it is the builder mode, but it is also the builder mode.

1. Intention
Separates the construction of a complex object from its representation, so that different representations can be created during the same creation process.

2. structure chart andCode
In Android, a large number of dialog box components are used. The Calling method is to build, splice, and represent them.

Builder constructs an alertdialoginstance object in create () by using settitle (), setmessage (), seticon (), and other methods.
Then the customer can show the alertdialoginstance object.

For this example, it is necessary for me to extend it to the name of the builder mode.
How to expand?
(1). create other concretebuilder
(2). create other elsedialog
(3). Step 1 determines that we 'd better create an abstract builder.
(4) create a context, inject the builder into it, and produce different dialog (or other UI) objects.

3. Results
(1). Creation Mode
(2). Different dialog can be produced, or other UIS can be produced. The production product can be very different, so there is no need to define abstract parent classes for the product.

Related Article

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.