Factory Method)

Source: Internet
Author: User

Factory Method)
Zookeeper

The Factory method mode is the class creation mode, also known as the Virtual Constructor mode or the Polymorphic Factory mode.

The purpose of the factory method mode is to define a factory interface for creating product objects and postpone the actual creation to the subclass.

Structure of the factory method mode:




Abstract Factory role: this role is at the core of the factory method model and is irrelevant to the application. Any factory class that creates an object in the mode must implement this interface. In the above system, this role is played by the java interface "Abstract Factory". In actual systems, this role is often implemented using abstract java classes.


Specific factory role: the role is a specific java class that implements the abstract factory interface. The specific factory role contains the logic closely related to the application and is called by the application to create product objects. This system provides three such roles, namely, the specific java class.


Abstract Product role: the super type of the object created in the factory method mode, that is, the product object's common parent class or interfaces. In this system, this role is played by the java interface extraction product. In actual systems, this role is often implemented using abstract java classes.


Specific product role: this role implements the interface declared by the abstract product. Each object created in the factory method mode is an instance of a specific product role.


For example:



Abstract Factory is the core of the factory method model, but it does not grasp the power of killing fruits or vegetables. On the contrary, this right is handed over to sub-classes, namely AppleGardener StawberryGardener and GrapeGardener.


Code List:

Abstract Product

VcfJqyjGu7n7KTwvcD4KPHA + pgltzybzcm9 "http://www.2cto.com/uploadfile/Collfiles/20150309/20150309082250123.png" alt = "\">


Specific product roles (grape)


Specific product role (Strawberry)


Abstract Factory


Specific Factory (Apple)


Specific Factory (grape)


Specific factory type (Strawberry)





Zookeeper

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.