[Design pattern arrangement Note 6] Summary of factory pattern and creator Pattern

Source: Internet
Author: User

[Guide]

[Design mode sorting Note 1] basic knowledge

[Design mode sorting Note 2] simple factory Mode)

[Design mode sorting Note 3] factory Mode)

[Design pattern sorting Note 4] abstract factory pattern (Abstract Factory)

[Design pattern sorting Note 5] creator pattern (builder)

[Design pattern arrangement Note 6] Summary of factory pattern and creator Pattern

[Design mode sorting Note 7] prototype)

[Design mode sorting Note 8] Singleton)

[Design mode sorting Note 9] appearance mode (facade)

... Later, including some examples

[/Guide]

 

 

The factory mode and creator mode are described above. To sum up, we will find such a rule:

(Tip: a small company started with only 40 employees)

 

The simple factory model is like a small company, so only one workshop is needed for the production of products. The boss verbally told the team lead in the workshop that direct production does not require any further approval, all the products are produced in this workshop. The factory class in the simple factory model is the workshop, and the static class is the production method directly called by the boss, only a small, non-complex system can be used. Let's take a look at this. If there are a lot of products that need to be processed continuously in the workshop, the formula obviously does not meet the production requirements.

 

(Note: after a period of development, the efforts of all employees, the company's expansion of production, the product from the first one, to dozens of now, the total number of employees also reached 2000)

 

The factory model is like this medium-sized company. The production of a product may be produced in a factory, and the approval documents of each department are required for production. Therefore, the static method is not suitable, therefore, the factory category in the factory model is set up for each product. There may be many factory categories, that is, a product is produced in a building like a factory, A medium-sized company may have many factories. Each plant produces one product. In the factory mode, this means that a product creates a factory class to return to the instance.

 

(Note: after a period of development, the efforts of all employees, the company's expanded production, and the product was also from the first to dozens of products, and found that many products have similar places, such as: Printing Products: printing textbooks, printing novels, printing magazines, are printed operation, electronic products: diode, transistor, and a series of product lines, including 5000 employees)

 

The image factory model is like this big company. Every product comes in and needs to be counted by abstract products, and then allocated to that series of products,ProgramIt is an abstract class of a series of products. For example, if a salesperson receives a sheet stamped with an envelope, the documentary needs to know the operation that the envelope needs to be printed, this product is divided into the Printing main door for production, so the program is also the same, the establishment of an abstract class for the following products to inherit. Abstract Factory classes also need to be created based on a series of products.

 

(Tip: after a period of development, the efforts of all employees, the company's production expansion, the number of subsidiaries is also growing, and the subsidiary needs to be assembled into the company to form a group company)

 

The Creator mode is suitable for this situation. Many similar products need to be assembled to form a new object.

 

If you are familiar with all the previous friends, please use the factory mode and creator mode to design the things around you. You can understand the design mode only by thinking more and doing more.

 

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.