Design Pattern-creator pattern (including 5 types)

Source: Internet
Author: User

Creator mode: the mode used to create objects. It abstracts the instantiation process. Improve the maintainability and scalability of the system to cope with changing needs! Common creation modes are as follows:

1. Factory mode: provides an interface for creating objects, but the subclass determines which class to instantiate. This encapsulates the object creation process.

For example, if there is only one product, multiple manufacturers can produce it. Both Audi and BMW can produce automobiles.

2. Simple factory mode: A factory object creates a series of product instances.

For example, KFC makes a series of products (hamburger, cola, Fries)

3. abstract Factory mode: provides a series of related or mutually dependent object interfaces, without explicitly specifying a specific class (the condition judgment statement in the abstract factory class is used. net reflection mechanism)

For example, KFC and McDonald's are both factories with a series of products (hamburger, cola, and Fries)

All three have the same thing in common: they are all instances of factory objects, and then instances of product objects are generated through instances of factory objects.

4. Builder mode: create a complex process object to encapsulate the created process. (For different similar objects, the factory is used to create different classes)

For example, a car consists of parts.

5. prototype mode: in the same factory mode, the creation of objects is also hidden for the customer. However, unlike constructing a new object by instantiating a class, the prototype generates a new object by copying an existing object.

(This design pattern series can be summarized as follows:[GofDesign Patterns],Thank you for terrylee's tech space and other network materials !)

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.