Summary of design patterns (3) Abstract Factory

Source: Internet
Author: User

This series mainly records what the design pattern intends to be, what issues it wants to solve, and when it can be used; how it solves it, master its structure diagram, remember its key code; be able to think of at least two of its application instances, one in life and one in software; What are the advantages and disadvantages of this model, and what use scenarios are there, what should I pay attention to when using it.

3. Abstract Factory

Intention: Provides an interface for creating a series of related or mutually dependent objects without specifying their specific classes.
Main Solution: Mainly solves interface Selection Problems

When to use: The system has more than one product family, and the system only consumes one of the products.

Solution: Define multiple products in a product family

Structure chart:

Key code: Aggregate multiple similar products in one factory
Application Instance: After work, there must be two or more clothes to attend some gatherings, such as business clothes (Complete Sets, a series of specific products) and fashion clothes (Complete Sets, a series of specific products ), even for a family, there may be business women's clothing, business men's clothing, fashion women's clothing, fashion men's clothing, these are also complete sets, that is, a series of specific products. let's assume that there is a situation (in reality, it doesn't exist; otherwise, it won't be possible to enter communism, but it is helpful to illustrate the abstract factory model). In your home, a wardrobe (specific factory) you can only store a certain type of clothing (set, a series of specific products). Each time you take this set of clothes, you will naturally need to take them out of this wardrobe. with OO, we can understand that all wardrobes (specific factories) are wardrobes (Abstract factories, each complete set of clothes includes a specific coat (a specific product) and trousers (a specific product). These specific jackets are actually jackets (Abstract products ), the specific trousers are also trousers (another abstract product ).

Advantages:1. When multiple objects in a product family are designed to work together, it ensures that the client always uses only objects in the same product family.

Disadvantages:It is very difficult to expand the product family. To add a product of a series, you must add code to the abstract Creator and add code to the specific product.

Use Cases:1. QQ For skin, a set of Change 2. generate different operating system programs

Note:Product Family is difficult to expand, product grade is easy to expand

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.