Bad taste of code [3]
Total returned directory
9. Primitive Obsession (basic type paranoid)
This is mainly manifested in the excessive use of basic types.
1. A basic type field that is always put together can be extracted from a class.
2. There is basic type data in the parameter column, which is the same as the eighth "Bad taste" and can be extracted into objects.
3. If you are selecting data from an array, replace the array with an object.
10. Switch Statements)
One of the most obvious characteristics of object-oriented is that the switch... case... statement is rarely used. Essentially, the problem with switch statements lies in repetition. You often find that the same switch statement is distributed in different locations.
1. If the switch statement is selected based on the type code, the polymorphism is considered.
2. If there are some selection cases in a single function, you can replace the parameter with a specific function.
11. Parallel Inheritance Hierarchies (Parallel Inheritance system)
There are two bad tastes:
1. When adding a subclass to a class, you must add a subclass to another class.
2. the prefix of an inherited system class name is the same as that of another inherited system class name.
Eliminate this repetitive strategy: an instance in one inheritance system references an instance in another inheritance system, and then migrates the Member
12. Lazy Class (redundant Class)
In fact, a class does not do so much work or has nothing to do.
1. If there is no big difference between the parent class and the Child class, combine them into one.
2. A class does not do much. Move all features of this class to another class, and then remove the original class.
13. Speculative Generality)
1. Try to handle unnecessary things with various hooks and special circumstances.
- An abstract class does not have much function. It combines Parent and Child classes.
- Unnecessary delegate, move all the features of this class to another class, and then remove the original class.
- Some parameters of the function are not used. Remove the parameters.
- The function name has a redundant abstraction meaning. Rename the function name.
2. The only user of a function or class is a test case.
In this case, delete such functions or classes together with test cases.
To Be Continued...