21 "bad taste"

zhaozj2021-02-08  419

1. Duplicated Code code is almost the most common odor. He is also one of the main goals of Refactoring. Code repetitions are often derived from Copy-and-Paste programming style. It is an important sign with him is a good system (see my duplicated code): http://www.erptao.org/download.php? Op = viewsdownload & SID = 6).

2. Long Method It is a traditional structured "of the whole". A method should have self-independent intentions, do not put a few intentions together, and I have a detailed description in my "Class and Long Method".

3. Large Class Class is that you have given too much responsibility to a class. The rules here are One Class One Responsibility.

4. DIVERGENT CHANGE is different from the content change rate in a class. Some states have changed one hour, and some will change once a few months; some states have changed because of this reason, while others changed once. Object-oriented abstraction is to isolate relatively unchanged and relative changes. Separate the side and the other aspect of the problem. This makes these relatively unchanged reuse. Every aspect of the problem changes can be reused separately. This coexistence coexistence makes it very difficult to reuse.

5. SHOTGUN SURGERY This is just the opposite of it. Changes to the system a place involve correlation changes in many other places. Status and behavior of these variations and changes in content should usually be placed in the same class.

6. The purpose of the Feature Envy object is to encapsulate and closely related to these states. If a class method is frequently calculated using a GET method to access the status of other classes, then you have to consider moving behavior to that class involving the number of status.

7. Data CLUMPS Some data is usually playing like a child: together in many class members variables, together in many ways to parameters ... .. These data should be independently formed independently.

8. Primitive Obsession Object-Oriented Novice is usually used to using several original type of data to represent a concept. For example, for the scope, they will use two numbers. For Money, they will use a floating point number. Because you don't use objects to express the concepts in the problem, this makes the code change difficult to understand, and the difficulty of solving the problem is greatly increased. A good habit is that the expansion language can provide the original type, use small objects to represent scope, amount, conversion rate, postal code, etc.

9. The switch statement based on the Switch Statement is the enemy of OO, and you should turn him into a subclass, State or Strategy.

10. Parallel Inheritance Hierarchies parallel inheritance level is the special situation of Shotgun Surgery. Because when you change a certain class in a level, you must change another level of parallel.

11. Lazy Class is a categorically categorous class. The maintenance of classes requires additional overhead. If a class takes too little responsibility, it should be eliminated.

12. Speculation generality A class implements the features and versatility of never use. Usually such a class or method unique user is TestCase. Don't hesitate, delete it.

13. Temporary Field A object's properties may only be meaningful in some cases. Such a code will be difficult to understand. Establish an object to hold such orphan attributes, move the behavior that only to him to this class. The most common is a specific algorithm that requires some variables that only the algorithm is only available.

14. The Message Chain message chain occurs when a customer requests another object to an object, and then the customer requires another object to this another object, and then request another object to this another object, so. At this time, you need to hide the dispatch. 15. One of the basic features of the Middleman object is package, and you often use it to achieve encapsulation. But this step can't be too far, if you find a large half of the way a class interface is assigned, you may need to remove this middleman.

16. Inappriate intimacy certain classes are too close, they spend too much time to go to the private parts of others. For humans, we may not be too false, but we should make our classes strictly abide by abstinence.

17. Alternative classes with diffracity Methods Methods Make the same thing have different function signatures, unanimously moved to the class level until the agreement is consistent.

18. INCOMPLETE LIBRARY CLASS is very difficult to build a good class library. Our large program work is based on class library. However, such a broad and univautable target puts a harsh requirement for the library builders. The library is not universal. Sometimes we will find that the library class cannot achieve the features we need. It is very difficult to modify the library class directly. At this time, you need to use a variety of means for refactoring.

19. Data Class objects include status and behavior. If a class is only a state, there is no behavior, then there is certainly something wrong.

20. The REFUSED BEQUEST superclass has passed a lot of behavior and status, while subclasses are only used in a small part. This usually means having a problem with your class level.

twenty one. Comments often feel that you have to write a lot of comments indicating that your code is difficult to understand. If this feeling is too much, you need a refactoring.

转载请注明原文地址:https://www.9cbs.com/read-497.html

New Post(0)