Creator mode Overview

Source: Internet
Author: User
The role of the Creator mode can be summarized as follows:
1. encapsulate the creation logic, which is not just as simple as a new object.
2. encapsulate the creation logic changes. The customer code should not be modified or modified as little as possible.
The Creator mode is used to improve the maintainability and scalability of the system and improve the ability to respond to changes in requirements!
--

These two ends are almost exactly the same as my article. I have not read the webcast, and it is a coincidence.
I googled the "creator mode". I used to rank first in this article. p
The following is my explanation of why the Creator mode is required.

---
Why do we need Creator pattern?
I believe that many beginners have such a problem. Why do we need the Creator mode?
However, when many people introduce the Creator pattern to others, they often pass through this problem (for example, my teacher ).
A: The Creator mode is used to create objects, while the mode is a summary of previous experiences. Therefore, the Creator mode is a good thing.

Do you need answer like this? What can we learn about Creator Pattern From this?
First of all, this is not the answer I need, and I only know that the Creator mode is used to create objects. (dizzy, it's not a nonsense to read this sentence)
So what is my answer?

Use code to illustrate the problem. (the source code is sometimes better than a thousand words)
First, a Mercedes-Benz was created.
Car car = new Benze ();
Suddenly our car changed to a BMW. OK, let me modify it.
Car car = new BMW ();

Imagine that there are countless such codes in our code. More than one (this is important)
So when you need to change the car in the future, do you need to modify our creation code one by one to change Benze to BMW.
Then we can use the factory to implement the following:
Car car = benzeFactory (). Factory ();
What is this? There is nothing to do. If you want to change the car, you don't have to change the original code to the following.
Car car = bmwFactory (). Factory ();

Yes?
This may be the case if only one of the Code is created here, but it is not the case if it is created in many places.
CarFactory carFac = new BenzeFactory ();
Car car = carFac. Factory ();
When you need to change the Car, you only need to modify one code: CarFactory carFac = new XXXFactory ();
Other places where a Car is created will never change, or the car Car = carFac. Factory ();
OK? Do you understand?

It is difficult to avoid modification, but we should try to modify only one.
I wonder if you are satisfied with this explanation.

The Creator mode is used to improve the maintainability of the Code (that is, the ability to cope with future changes ).

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.