Iterative evolution of the system

1. Achieve neatness through overlapping design

  • Run all tests
  • Do not repeat
  • Express the intent of the programmer
  • Minimize the number of classes and methods
  • The above rules are arranged in order of importance

2. Simple Design Principle 1: Run all tests

  • Design must produce a system that works as expected. This is the first factor
  • Systems that are fully tested and consistently pass all tests are testable, not verifiable, and should never be deployed online
  • As long as the system is testable, it leads to designs that keep the classes short and single-purpose
  • Tightly coupled code makes it difficult to write tests
  • By following simple, clear rules for writing tests and continuously running them, systems move closer to OO’s goal of low coupling, high cohesion, and writing tests leads to better design

3. Simple Design Principle 2: Refactor

  • With tests, you can keep your code and classes clean by incrementally refactoring your code
  • Testing eliminates the fear that cleaning up your code will break it
  • Three rules: Eliminate duplication, ensure expressiveness, and minimize the number of classes and methods

4. Do not repeat

1. Repetition is the enemy of a well-designed system

2. Extremely similar lines of code are, of course, repetitions, as well as implementation repetitions and other forms

int size(a);
bool isEmpty(a);
Copy the code

These two methods can be implemented separately, but you can eliminate duplication by using size in isEmpty.

bool isEmpty(a){
 return size()==0;
}
Copy the code

Eliminate duplication not only from a line of code standpoint, but also from a functional standpoint.

3. SRP principle is violated when we carry out common extraction, so we can divide the new method into another class to achieve reuse. “Small scale reuse” can greatly reduce system complexity, to achieve large-scale reuse, must understand how to achieve small scale reuse

4.Template method patternIs a general technique for removing high-level repetition

5. Expressive

  • The major cost of a software project is long-term maintenance, and the code should clearly express the intent of its author
  • This can be expressed by choosing a good name ==
  • This can be expressed by keeping functions and class sizes short. Short classes and functions are usually easy to name, easy to write, and easy to understand.
  • This can be expressed by adopting standard nomenclature
  • Well-written unit tests can also be expressive, and one of the main purposes of testing is to act as documentation through examples.
  • The most important way to be expressive is to try

6. Have as few classes and methods as possible

  • The sheer number of classes and methods, sometimes led by pointless dogmatism, should have been more practical
  • The goal is to keep the whole system short (lowest priority) while keeping functions and classes short

7. To summarize

These four rules, in fact, most of the previous content is also around these, is the author deliberately made a small summary of the previous content, and put here, can let us combine the previous content to have a deeper understanding of these four valuable experience.

8. References

The way of clean code blog.csdn.net/zhangyunfei… www.jianshu.com/p/c44eca6ad…

Pay attention to the public account “Programmer interview”

Reply to “interview” to get interview package!!

This public account to share their own from programmer xiao Bai to experience spring recruitment autumn recruitment cut more than 10 offer interview written test experience, including [Java], [operating system], [computer network], [design mode], [data structure and algorithm], [Dacheng face by], [database] look forward to you join!!

1. Computer network —- Three times shake hands four times wave hands

2. Dream come true —– Project self-introduction

Here are the design patterns you asked for

4. Shocked! Check out this programmer interview manual!!

5. Teach you the interview “Profile” word for word

6. Nearly 30 interviews shared