Factory method Pattern of design pattern

Source: Internet
Author: User

Factory method Mode: Defines a factory interface that creates product objects, deferring actual creation to subclasses. The Core factory class is no longer responsible for the creation of the product, so that the core class becomes an abstract factory role and is responsible only for the interfaces that the specific factory subclasses must implement, and the benefit of abstraction is that the factory method pattern allows the system to introduce new products without modifying the specific factory roles.
Factory (Abstract Factory role): This is the core of the factory method pattern, which is independent of the application. Any factory class of objects created in the schema must implement this interface.
Concretefactory (Specific factory role): This is the specific factory class that implements the abstract factory interface, contains logic that is closely related to the application, and is called by the application to create the Product object.
Product (abstract product role): The common parent or co-owned interface of the production object created by the factory method pattern.
Concreteproduct (Specific product role): This role implements the interface defined by the abstract product role. A specific product has a specific factory-created, often one by one correspondence between them.

The difference between a factory method pattern and a simple factory model:

Simple Factory mode: determines which product class object is created by the parameters passed in, and the core factory class is responsible for the creation of the specific product class object, resulting in the need to modify the core factory class each time a new product class is added.

Factory method Mode: The Core factory class is responsible for defining only the methods that a specific factory subclass must implement, no longer responsible for the creation of specific products, and deferring the actual creation work to the specific factory subclass.

Factory method Pattern of design pattern

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.