Design mode 1

Source: Internet
Author: User
3. The difference between abstract Factory mode and factory method mode
It can be said that the factory method pattern is an abstract factory model of extreme situation, and abstract factory model can be regarded as a generalization of the factory method pattern.
(1) In fact, the factory method pattern is used to create a hierarchical structure of the product, while the abstract factory pattern is used to create a hierarchical structure of multiple products. Factory method creation generally there is only one way to create a product. Abstract factories generally have multiple methods to create a series of products.
(2), the factory method pattern has only one abstract product class, but the abstract factory pattern has several. Factory-mode-specific factory classes can create only one instance of a specific product class, while abstract factory patterns create multiple.

In short->
Factory method Pattern: An abstract product class that can derive multiple specific product classes.
An abstract factory class that can derive multiple specific factory classes.
Each specific factory class can create only one instance of a specific product class.
Abstract Factory Pattern: Multiple abstract product classes, each abstract product class can derive multiple specific product classes.
An abstract factory class that can derive multiple specific factory classes.

Each specific factory class can create instances of multiple specific product classes.




"open-closed" principle

The "open-closed" principle requires that the system be open to the extension and closed to modification. The extension achieves the purpose of enhancing its functionality. For systems that involve multiple product families and multiple product hierarchies, enhancements include two aspects:

Add Product family: Abstract Factory very good support of the "open-closed" principle.

Increase the grade structure of the new product: Need to modify all the factory roles, not very good support for the "open-closed" principle.

In combination, the abstract factory model supports the addition of new products in an oblique way, which facilitates the increase in the family of new products, and does not provide such convenience for the increase in the class structure.




The builder pattern is suitable for the construction of complex objects and its representation, when the algorithm for creating complex objects should be independent of the components of this object and how they are assembled

prototype Mode

The client simply doesn't know which class to instantiate.

It is only known to replicate, but the specific instantiation of the case, it is ignorant, so that the client is hidden,

At the same time, copying an object would generally be more performance than creating an object (sometimes, of course, it's just a general situation),





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.