|
Now you have a perceptual knowledge of "What is a design pattern". Some people may ask: "Why do you want to learn design patterns ?" There are many reasons, some are very obvious, and others are not so obvious.
The most common reason for learning models is that we can use them:
● Reuse solutions-by reusing well-known designs, I can take advantage of solving problems first and avoid repeating the same mistakes of my predecessors. I can benefit from the experience of others, and I don't need to design a solution for problems that always repeat.
● Establishing general terms-communication and collaboration in development both require a common vocabulary basis and consensus on issues. The design model provides a common benchmark in the project analysis and design phases.
The model also provides us with a high-level perspective of observing problems, designing processes, and object-oriented, which will free us from the shackles of "premature details processing.
When you finish reading this book, I hope you will agree that this is one of the most important reasons for learning the design model. It will change your mindset and make you a more efficient analyst.
To illustrate this advantage, I would like to cite a conversation between two carpenter about "How To Make drawers for cupboards.
Imagine that two carpenter was discussing how to make a drawer for the cupboard.
Carpenter A: How do you think we should make these drawers?
Carpenter B: Well, I think I should do this: I saw the wood straight down, and then saw it 45 ° back, and then saw it straight, then we switch to a 45 ° back saw, and then we went straight down the saw, and then ......
Now, you have to figure out what they mean!
Is this description confusing the cloud? What advice did carpenter B provide? This is often the case with details! Let's try to draw out his narrative.
It sounds like a stranger.CodeReview? One in the reviewProgramYou can describe your Code as follows:
Then, here I use a while loop ...... Then there is a series of If statement execution ...... Here I use a switch statement to process ......
What you get is a description of the Code details, but you have no clue about "what is the program to do" or "Why!
Of course, serious professional carpenter may not speak like this. The actual situation should be as follows:
Carpenter A: should we use a dove tail or a oblique slogon?
Are there any essential differences? Carpenter is now discussing the essential differences in solutions to a problem. They have a higher level of discussion and are more abstract, thus avoiding getting stuck in the details of a specific solution.
When the carpenter talked about the "slogan", his mind had the following features of the solution:
● It is a simpler solution-easier to create with a half slice. You only need to sawing the wood to produce a 45 ° slope, and then splice it with a nail or wood (as shown in Figure 5-2 ).
● It is lighter-the oblique half-width is less powerful than the dove-tail half-width. Under heavy pressure, the system will not be able to maintain tensortium.
● It is not very eye-catching-A saw surface of the Oblique slogan is less conspicuous than the multiple saw surfaces of the dove tail slogan.
Figure 5-2 oblique slogan
When the carpenter talked about the "dove-tail", another characteristic emerged in his mind. These features may not be obvious to the outside world, but any carpenter will understand the following:
● It is a more complex solution-there are more problems involved in the production of a dove tail. Therefore, the cost is higher.
● It is not easily affected by the temperature and humidity-when the temperature and humidity change, the wood will expand or contract, but the dove tail is still able to maintain strong.
● It has nothing to do with the fastening system-in fact, it does not even need to rely on glue.
● It looks more pleasing to the eye-if well-made, it will be very beautiful.
That is to say, the dove tail is a solid, reliable, beautiful, but the production is complicated (so the cost is also relatively high ).
So when carpenter Jia asks:
Should we use a dove tail or a oblique one?
The question he really asked is:
Should we use a high-cost, beautiful, and durable code, or should we just use a fast and unattractive code to stick to the end of the check?
We should say that the carpenter's discussion is actually carried out at two levels: on the surface of their discourse, they have a higher level than the actual content of the conversation, and the layers cannot hear it, the meaning is rich. This higher level is the level of the carpenter model, which reflects the real design problems in the carpenter's eyes.
In the 1st cases, carpenter B Discussed the implementation details of the slogan, but blurred the real problem. In the 2nd cases, the carpenter shall decide the type of tensor to be used based on the cost and joint nature.
Who is more efficient? Who are you more willing to work?
When I say "patterns help increase the level of thinking", this layer of meaning is contained. From the content after this book, you will understand that if you can improve your thinking level, new design methods will also emerge. This is exactly the power of the model.
|