2. Abstract Factory (Abstract Factory mode, Toolkit)

Source: Internet
Author: User

Abstract Factory (Abstract Factory mode, Toolkit)

It is the most abstract and general form of the factory model in all forms. Through the interface provided by the abstract factory, the client can create product objects in multiple products without specifying specific product types.

 

Applicability:

1. A system must be unrelated to how its product class is constructed, combined, and presented.

2. A system must be associated with one of the product families.

3. Agree that products of the product family are used together. This is an important constraint that must be reflected in the system design.

4. You provide a product library that only displays their interfaces rather than implementations, so that the client does not rely on implementation.

 

Structure:

1. Abstract Factory: Declares the interface for building (production) Abstract Factory Product Operations.

2. The specific factory (cconcretefactory): implements the operation of building (production) Abstract products.

3. Abstract product: Declares the interface of a certain type of object.

4. Product (cconcreteproduct): A product object to be built is defined relative to a specific factory. And implements the abstract product interface.

5. Customer (cclient): Build and obtain the final product object by using the abstract factory and the interface of the abstract product declaration.

 

Generally, a factory-class instance is created at runtime. And create the specific products for the specific factory respectively. To build different product objects, you must use different factories. The abstract factory provides an interface for producing products, but instead of building these products, it entrusts a factory of Its Derived classes to create product objects.

UML diagram:

Temporarily omitted. Haha

CodeTemplate:

Temporarily omitted.

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.