Simple factory, abstract factory, factory method difference

Source: Internet
Author: User

1. Simple factory:

The factory class in a simple factory contains logical judgments that can be dynamically created based on the client's choice, removing the client's reliance on the specific product. Note that simple factories violate the principle of opening and closing in design mode, so simple factories are not design patterns.

Constitute:

A specific factory class that contains logical judgments;

An abstract product class that can derive multiple specific product classes.

2. Factory Method Mode:

Define an abstract factory class, which is responsible for developing specifications in this abstract factory class, putting the actual creation of the product into the subclass. The Core factory class is no longer responsible for the creation of the product, so that the core class becomes an abstract factory role, only responsible for the specific factory subclass must implement the interface, relative to the simple factory can make the system without modification of the factory, the introduction of new products. Each specific factory class can only create an instance of a specific product class.

Constitute:
An abstract product class that can derive a number of specific product classes.
An abstract factory class that can derive a number of specific factory classes.

3. Abstract Factory mode

Abstract Factory mode refers to a factory pattern that is used when there are multiple abstract roles. Abstract Factory mode provides the client with an interface that enables the client to create product objects in multiple product families without having to specify the product's specific circumstances. Abstract factories have multiple abstract product classes relative to the factory method pattern, and each specific factory class can create instances of several specific product classes. Rather than as a factory method, a factory can only create one product.

Constitute:
Multiple abstract product classes, each abstract product class can derive multiple specific product classes.
An abstract factory class that can derive a number of specific factory classes.

Simple factory, abstract factory, factory method difference

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.