Java design mode Factory mode

Source: Internet
Author: User

Factory mode concept:

1 instantiate the object, replacing the new operation with a factory method.

2 Factory mode includes factory method mode and abstract Factory mode.

3 Abstract Factory mode is an extension of the factory method pattern.

Factory mode Intent:

1 defines an interface to create objects, which subclasses decide which classes to instantiate.

2 instantiation work is given to subclasses to implement.

Suitable for the Factory mode situation:

1 Create a similar set of objects.

2 You cannot foresee which class instance needs to be instantiated.

3 Consider extensibility and do not rely on product class instantiation details.

Factory method Pattern Class diagram:

  

Abstract factory Pattern class diagram:

  

  

  

The factory method model produces multiple products of the same class, and a specific factory in the abstract factory model produces a product family divided by multiple product hierarchies.

Resources

Factory mode Overview

Java design mode Factory mode

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.