About factory models

Source: Internet
Author: User

Let's talk about the simple factory model, factory method model, and abstract factory model:

Simple factory pattern ):The factory class contains the necessary logical judgment, and the related class is dynamically instantiated Based on the client selection conditions. That is to say, the product creation logic is concentrated in a factory class, and the client only needs to pass different parameters to the factory, in this case, a factory creates a product, and all the specific factories inherit from an abstract factory. for the client, there is no dependency with the specific product;

Factory method pattern ):Define the interface used to create objects in advance so that the subclass decides to instantiate a specific class, that is, add interfaces between the factory and the product, and the factory is no longer responsible for product creation, the interface returns a specific class instance based on different conditions, which is implemented by a specific class instance;

Abstract factory pattern ):Provides an interface for creating a system or mutually dependent objects. You do not need to specify a specific class. Abstract Factory, as its name says, abstracts factory interfaces, so it targets multiple equal level structures, the object creation principle is to divide the objects to be created based on objects with similar functions.

Simple factory does not belong to 23 basic design patterns. It is a special case of abstract factory patterns. The difference between Abstract Factory methods and factory methods lies in their different abstract objects: factory methods abstract products, abstract Factory abstraction targets factories. Therefore, we can think that the factory method is an extreme situation of abstract factories. The factory method mode is used to create a hierarchical structure of a product. Generally, there is only one method to create a product; abstract Factory is used to create the hierarchical structure of multiple products. Generally, there are multiple methods to create a series of products.

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.