Simple comparison of three factory models and three factory models

Source: Internet
Author: User

Simple comparison of three factory models and three factory models
For a long time, I wanted to thoroughly understand the design pattern, suffer from laziness, and I have been thinking about it all the time. Recently I have arranged some time, as if I had a lot of time out of thin air. Now I am working on something in the design pattern. The learning of the design pattern is necessary, especially for optimizing the code structure, the most obvious is the withdrawal.
1. Simple factory Model
UML:

Advantages and disadvantages:
This method demonstrates the advantages of the basic factory model. You do not need to pay attention to the creation process, but only need to tell the factory what it wants. The disadvantages of this method are also obvious, which violates the principle of opening and closing the design model (opening and closing the extension), because the factory must be rebuilt to increase the product.
2. Factory method mode
The factory method mode is used to solve the disadvantages of the simple factory mode. The factory method mode has an abstract factory. Different products that users need must inherit different instance factories of the abstract factory to create, in this way, whenever users need to produce different products, they only need to instantiate the corresponding factory instance and product model. The scalability is much better than that of the simple factory, but its disadvantages are also obvious, it is necessary to create many factory instances, and the number of classes increases a lot.
3. Abstract Factory Model
Compared with the factory method model, the abstract factory model can produce multiple products and have multiple abstract products. Each instance factory is equivalent to a family with the same product types among the many families, the instance factory has the function of customizing different types of accessories for a product.

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.