Importance of basic skills – (design mode)

Time:2022-5-6

Code quality is both designed and iteratively optimized. In other words, whether it is the early product demand analysis, architecture design, or the later detailed code design and coding, it is inseparable from good design.
Programming is the basic skill of every programmer. However, most people are only enthusiastic about new technologies, but few people are willing to settle down and spend months or even a year or two to review basic knowledge and practice basic skills.
In the face of the wave of so-called “new technology”, I can’t see through the simple law behind it, but I just stand still with a hammer in the East and a hammer in the West.
When I was really involved in coding practice and design, I suddenly found many advantages of design mode, such as improving the efficiency of source code reading, quickly solving problems in short-term projects, reducing maintenance costs and so on.
In the process of constantly learning and practicing design patterns, I have gained a lot of practical experience, including programming skills, architecture design inspiration, interview skills and so on
How to learn design patterns well
With the goal of learning design patterns, we have to find the right way to learn design patterns.
The most effective way to learn design mode is: Active Learning + deliberate practice.
In practice, few people tell you how to design a program. They only ask for one result – to make a good program and run it.
In the face of such requirements, you can often only be in a passive learning state: you can learn what you need in the task, a hammer in the East and a hammer in the West. Although this is effective in the short term, in the long run, your knowledge accumulation speed is actually very slow. Therefore, if you want to learn design patterns well, you have to give up this passive learning method and take the initiative to learn with goals and systems: find good materials, analyze and understand, and open your mind.
Do you still have the following doubts?
1. The design pattern is often asked in the interview, but it is rarely used in practical work;
2. The sample code of each mode is very familiar, but the actual coding always feels inadequate and difficult to implement;
3. Many system designs look like many modes, but I don’t know whether to use one mode or multiple modes;
4. Besides being useful in the coding stage, the design pattern seems to be of little use in design.
In fact, the key to these puzzles at that time was not that the design pattern was too abstract or difficult to apply, but that I might not understand the application scope and background of the design pattern from the beginning: what problem does the design pattern solve? Why Abstract such scenes? How to solve these problems?
Common misconceptions about design patterns
It is precisely because we do not understand the scope and background of these applications that most of the time we are always “mechanically copying” the design mode, thinking that we are applying the design mode, but we do not know that we have been misunderstanding the design mode before we get started, and use it indiscriminately without control. Finally, we introduce a lot of unnecessary trouble.
Therefore, if you want to learn design patterns well, you have to pick up these misunderstandings.
Myth 1: classic patterns are too abstract to learn
When it comes to design patterns, does your first reaction think of the “classic” book “design patterns: the foundation of reusable object-oriented software” by the gang of four GOF? Or think of the 23 “classic” patterns?
Indeed, design patterns are too classic, but classics also bring a problem: they are too abstract and difficult to understand quickly. For you who don’t have much spare time, reading Abstract classics is even more difficult.
In short, the common experience of design patterns summarized from different projects is to help us quickly understand the existing system and find out the common laws. If we don’t have enough experience or thinking, it is easy to introduce wrong design and cause more trouble.
Therefore, “classics are too abstract” is just a fact. As long as you are willing to take the time to read them carefully, it is not difficult to learn them.
Misunderstanding 2: the design mode is too single, and it is difficult to implement complex business scenarios
Now, there are two very interesting phenomena about design patterns
In theory learning, almost all developers think it is very important.
In working practice, most developers can’t find a suitable application scenario in the project.
In fact, the key point of this conflict is that the scope of design patterns to solve problems is not clear. In other words, design pattern is not a full scenario solution, it needs to consider the scope of application.
For example, in the field of object-oriented language Java, how to maximize the power of inheritance and combination of object-oriented language? How to decouple program interdependence? Design patterns provide some answers.
If you are now receiving the design task of a complex system, for example, how to design a second kill system? You need to care not only about the implementation of business functions, but also about the mutual configuration between different development members and server resources. At this time, the adapter mode, policy mode and state mode in the design mode come to your mind… The help is not so obvious to you, because you haven’t reached the stage where you need detailed implementation.
In fact, the design pattern is proposed to solve the limited problems in the limited field. For example, how to implement reusable software for the technical framework of non business scenarios? How can we improve programming efficiency for more people? Generally recognized tools such as spring, netty, mybatis and JDK can be seen everywhere, but not only the design pattern itself.
Therefore, you can’t treat the design pattern as a general solution, or think that it should solve problems beyond the scope. You must consider its scope of application, otherwise the problem can’t be effectively solved.
Myth 3: since the model is easy to use, everything is a model
Good design never depends on how many patterns are used, but on how to make rational use of the design idea of patterns and how to use patterns to solve real problems.
Therefore, learning design patterns is to inspire our thinking, not “holding a hammer in hand and looking for nails all over the world”.
How to learn design patterns correctly
First of all, we should straighten out our mentality.
Design pattern is not a panacea, not a silver bullet. The problems that design pattern can solve are actually limited. You should always maintain a normal attitude and correctly analyze the problems that design pattern can solve and cannot solve.
Secondly, make clear the background knowledge of design patterns
For example, how are design patterns defined? Historical evolution and changes of design patterns? What are the applicable areas of design patterns? What areas are not applicable? How to analyze and use it in combination with practice?
When learning a knowledge, if you always ignore the relevant background knowledge, over time, you will develop the habit of accumulating piecemeal knowledge – collecting a lot of data, but disassembling and absorbing very little. When learning related knowledge, you will find that the original knowledge will be gradually connected and connected, which is an action to get twice the result with half the effort.
Thirdly, try to have the habit of expert independent thinking
In the Internet age, there is no shortage of materials and methods, but experts who can solve complex problems. The reason why a master becomes a master is that a master does not stick to the high or low of a certain knowledge, but maintains a wise judgment and always moves towards a firm goal.