The abstract factory pattern of C + + implementation of design patterns

Source: Internet
Author: User
Tags abstract

Problems to solve:

In the system a,b,c three components must be used at the same time, but the same A1 and A2 of a have common features but are mutually exclusive, B,B1,B2 and C,C1,C2 are the same. For example, to create a system that can run in a Windows environment of different operating systems, there are Unixbutton and Unixtext,win underneath Unix, as well as Winbutton and Wintext, Unixbutton and Unixtext must be used in a system UNIX, and Winbutton and Wintext can only be used under win. But Winbutton and Unixbutton both have the same characteristics, such as after the press will trigger events, such as he has a text description and so on, but Winbutton and Unixbutton are not mixed.

Then this problem can be solved in an abstract factory:

How to choose to use Winbutton in abstract Factory mode, Wintext, have specific factory class winfactory to be responsible for, because they contain the logic that chooses the appropriate product object, so it is closely related to the business logic of the application system. The abstract factory class is responsible for defining interfaces, and he is the core of the abstract factory model.

And Winbutton/macbutton is a product family, there are common characteristics, their specific characteristics are abstract product class or interface to define and describe. But their specific implementation has a specific product class is responsible for, these are the end of what the client wants, so its internal must be full of application system business logic (triggering logic/style logic, etc.).

Class Diagram Structure:

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.