Interpreting design Patterns----Abstract factory patterns (abstractfactory pattern)

Source: Internet
Author: User
Tags abstract

I. Description of the pattern

There are a series of objects in my program, like we're going to have a bowl of rice, a cup of coffee (Coffee) ..., to take advantage of them, we have to generate them in the program according to the user's requirements, and then call the new operator one at a, This way the client will know the corresponding class information, the generated code is obviously not flexible. So we can not use the specific classes in the code, but just to show what we need, and then we can get the object we want?

This is certainly possible, according to Gof in the book "Design Patterns", to create objects such work should be in the creation pattern. Friends who are familiar with the intent of various design patterns will quickly conclude that "providing an interface to create a series of interrelated or interdependent objects without specifying their specific classes", at least "without specifying their specific classes", meets our requirements. OK, that's the intention of the abstract factory model.

Second, the mode of intent

Provides an interface to create a series of related or interdependent objects without specifying their specific classes.

UML Diagram of Pattern:

Iv. Model Participants

Abstract Factory role: This role is at the heart of the factory approach model, which is irrelevant to the business logic of the application system.

Specific factory (concrete Factory) Role: This role creates an instance of the product directly under the call of the client. This role contains the logic to choose the right product object, which is closely related to the business logic of the application system.

Abstract Product Role: The class that holds this role is the parent class of objects created by the factory method pattern, or the interfaces they share.

Specific product (concrete product) Role: Any Product object created by the abstract factory pattern is an instance of a specific product class. This is what the client ultimately needs, and its interior must be full of the business logic of the application system.

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.