I believe that many programmers have realized the importance of basic knowledge and feel that they need to build a solid foundation to go further, but still have some doubts about how to translate that basic knowledge into development “productivity.” As a result, you may have read a lot of basic books, such as operating systems, composition principles, compilation principles, etc., but still feel confused and feel that they are not useful in development, at least in normal CRUD business development. In fact, this basic knowledge does not translate directly into development “productivity.” But it can subtly and indirectly improve your understanding of technology.

However, I don’t think design patterns are the same as operating systems, principles of composition, principles of compilation, and other basic disciplines. Although it is a basic knowledge, it is more like data structures and algorithms, and design patterns can improve your development ability more directly than those more basic disciplines. As I said in the opening paragraph, if data structures and algorithms teach you how to write efficient code, design patterns teach you how to write high quality code that is extensible, readable, and maintainable, so they are directly related to normal coding and have a direct impact on your ability to develop.

Still, you may feel that design patterns are a dragon slayer that looks great but doesn’t work in normal development. With that in mind, let’s talk more specifically about why we learn design patterns.

  1. Respond to interview questions about design patterns

As with algorithms, the most utilitarian and immediate purpose of learning design patterns may be to prepare for an interview

Whether you are a front end engineer, a back end engineer, or a full stack engineer, design pattern questions are one of the most frequently asked questions in job interviews. In particular, some large companies such as BAT and TMD pay more attention to the basic skills of candidates and often examine candidates with problems such as algorithms and design patterns.

So when I go to a job interview, I always prepare and review design patterns in advance. While it’s not always the case that you’re asked in an interview, if you do, a bad answer is a failure, and the interview basically fizzles. Therefore, in order to make sure that there is no mistake and get rid of the dilemma that I cannot answer once I am asked, I always prepare for the most likely questions such as design patterns.

Of course, I’m not cramming. I usually pay attention to the accumulation of knowledge related to design patterns, so I have a good foundation. As long as I spend a short time before each interview to review, I can be confident to go to the interview, instead of worrying about being asked questions, which will affect the normal performance of the interview.

So if you don’t want design patterns-related questions to be your weakness, follow me through on this column and you won’t be afraid to ask design patterns-related questions in future interviews.

  1. Say goodbye to bad code that people make fun of

We often say, “Talk is cheap, show me the code.” In fact, code ability is the most basic ability of a programmer, is the basic skills, is the most direct measure of the basic literacy of a programmer. The code you write is, in effect, your calling card.

Although I have been working for nearly ten years, I have never been out of the coding field, and I still write code every day, review and instruct colleagues to write code, and refactor the bad code of legacy systems. Over the years, I have seen a lot of bad code, such as poorly named, poorly designed classes, poorly layered, no modular concept, poorly structured code, high coupling, and so on. This code is very difficult to maintain, add or modify a feature, often pull the whole body, let you have no way to start, I wish to delete the whole code rewrite!

Of course, over the years, I’ve seen a lot of code that really blew my mind. Every time I see good code like this, I immediately feel a lot of love and recognition for the author. No matter what level the person is in the company, the code shows that he is a highly potential employee with solid foundation and a promising future. So writing good code makes you stand out from the rest of the team.

Therefore, this book is not only about design patterns, but more importantly, through practical examples, I will teach you how to avoid the aforementioned code problems, say goodbye to bad code, write commendable good code, and become a code benchmark in the team! Also, write beautiful code and you will feel a sense of accomplishment.

  1. Improve the ability to design and develop complex code

Most engineers are familiar with programming languages, tools, frameworks, and so on, because their daily work is to populate the framework with code based on business requirements. Actually, that’s what I did when I first started working. Relatively speaking, this kind of job does not require you to have strong code design ability, but simply understand the business and translate it into code.

However, one day, my leader asked me to develop a general function module unrelated to business. Faced with such slightly complicated code design and development, I found that I was out of my strength and DIDN’t know where to start. Because I know that it may not be complicated to write code that is easy to expand, easy to use, and easy to maintain.

How to layer and module? How should classes be divided? What attributes, methods should each class have? How do you design interactions between classes? Inheritance or composition? Should I use interfaces or abstract classes? How to achieve decoupling, high cohesion and low coupling? Should we use a singleton pattern or a static approach? Do I create objects in factory mode or do I just new them out? How to avoid introducing design patterns to improve scalability and reduce readability? . All kinds of questions, all of a sudden crowded me

At that time, I did not have much understanding and accumulation of knowledge related to design patterns (including design patterns, design principles, object-oriented design ideas, etc.), so I was at a loss for a while. Fortunately, I realized the importance of this knowledge, so IN the years of development, I have been deliberately training and accumulating this ability. In the face of complex code, function, system design and development, I also become more and more handy, with ease. It has become a habit for me to write high-quality code. The code I write inadvertently can be used as a model for my colleagues to learn and copy, which has also become one of the highlights of my career.

  1. Let read the source code, learning framework twice the result with half the effort

For a programmer who has pursuit, the accumulation of technology should have both breadth and depth. Many technical people have been aware of this early, so in the learning framework, middleware, will take time to study the principle, read the source code, hoping to accumulate depth, rather than just a superficial knowledge, can use it.

From my experience and feedback from colleagues, when some people look at the source code, they often encounter questions that they can’t understand and can’t read. I don’t know if this has ever happened to you? In fact, the problem is simply that you don’t have enough basic knowledge and ability to read the code. Why do I say that? Excellent open source projects, frameworks, middleware, the amount of code, the number of classes will be relatively large, the class structure, the relationship between classes is very complex, often called to call. Therefore, in order to ensure the extensibility, flexibility and maintainability of the code, there are many design patterns, design principles or design ideas used in the code. If you don’t understand these design patterns, principles, ideas,

When you look at the code, you may not understand the author’s design ideas, and it can take a long time to understand some obvious design ideas. On the other hand, if you are familiar with design patterns, principles, and ideas, and can immediately understand the author’s design ideas and intentions, you can quickly free up your brain to focus on other issues, and the code will be easier to read.

In fact, in addition to the problem of not understanding and reading, there is another hidden problem, you may not find yourself, that is, you think you understand, in fact, you don’t get much of the essence of it! Because good open source projects, frameworks, middleware, it’s like a fighter jet of all kinds of cutting-edge technology. If you want to analyze its principles and learn its technology, and you don’t have accumulated profound basic skills, even if this fighter plane is put in front of you, you will not be able to fully understand its essence, only to understand the surface, watch the excitement.

Therefore, learning design patterns will not only make it easier for you to understand open source projects, but also help you to understand the underlying technology.

  1. Prepare for your career development

Ordinary, low-level development engineers, only need to framework, development tools, programming language proficiency, and do a few projects to practice, basically can cope with the usual development work. However, if you do not want to be a low-level coder all your life, want to grow into a technical expert, a bull, a technical leader, and hope to have higher achievements and better development in the workplace, it is necessary to pay attention to the training of basic skills and the accumulation of basic knowledge.

If you look at the code written by Daniel, or excellent open source projects, the code is very beautiful and of high quality. If all you do is use a good framework, talk a good architecture, but write bad code, and let people see at a glance that there are many things that don’t make sense and can be improved, you will never be the “tech guru” that others think of. Also, as you get to a certain stage in the technical career path, you will have to take on mentoring and training of junior employees, newcomers, and code review. At this point, if you’re asking yourself “What is good code? How do you write good code?” No, so how to guide others, how to convince them?

In addition, if you are a technical leader, responsible for the overall development of a project, you need to be responsible for the development schedule, development efficiency and project quality. You don’t want your team to pile up so much junk code that the project becomes unmaintainable, and it takes a lot of work to add and fix a feature, which ultimately slows down the team’s productivity.

In addition, the low quality of the code will also lead to frequent online bugs, difficult to troubleshoot. The entire team is stuck fixing low-level bugs and adding patches to bad code. A well-designed, easy-to-maintain system frees up our time to do things that are more meaningful and enhance our own and team capabilities.

Finally, when you become a leader or senior engineer or technical expert in a team, you are bound to be responsible for the recruitment of part of the team. At this point, if you are looking at a candidate’s design skills and code skills, design pattern-related questions are a good place to look. However, I also learned that many interviewers are not very familiar with design patterns, and can only use some simple singleton patterns and factory patterns to investigate candidates, and the questions are often divorced from practice, for example, how to design a restaurant system, parking lot system, ticketing system and so on. These questions have been around for thousands of years and offer little insight into the candidates’ abilities. In my column, there are over 200 design pattern questions for real project development. Read on and you’ll become a design pattern guru so you don’t have to be embarrassed to interview candidates with the same old, out-of-touch questions.

The key to review


Today, we talked about why we need to learn about design patterns. To summarize, there are five main points:

  • Answer questions about design patterns in the interview;
  • Say goodbye to writing bad code that people make fun of;
  • Improve the design and development ability of complex code;
  • Let read the source code, learning framework multiplier;
  • Prepare for your career development.

As a basic knowledge that is directly related to coding and development, design patterns are something you should start learning now. To learn early, the future projects can be used to exercise, each line of code is the use and deepening of internal work, can benefit a whole career.