Detailed bad habit of Sonar

Bad taste 22 kinds of code, in one sentence: 

If a piece of code is unstable or there are some potential problems, then the code will often contain some obvious traces. 
As to food spoilage before, often will be issued the same number of odors. 
We control these traces is called "code smell." 

Reference: 
http://blog.csdn.net/sulliy/article/details/6635596 
http://sourcemaking.com/refactoring/bad-smells-in-code 
Code Smells 
Duplicated Code -------- ( repeat the code) is difficult to maintain. 
[Solution]: extract a public function. 
Long Method ------------ (a function of length) difficult to understand. 
[Solution]: split into several functions. 
Large Class ------------ (large category) difficult to understand. 
[Solution]: split into several classes. 
Long Parameter List ---- (multi-parameter) difficult to use, difficult to understand. 
[Resolution]: The package structure or parameters into classes. 
Divergent Change ------- (universal category) diverge try to modify, change a lot of demand, will move him. 
[Solution]: demolition, along with the always changing things on together. 
Shotgun Surgery -------- (Tiannvsanhua logic) shotgun try to modify, change a requirement when you want to change a lot of class. 
[Resolution]: The respective modification point, together, into a new abstract class.
Feature Envy ----------- (affair function) uses a lot of other members of the class  
Temporary Field --------- ----------------------- (temporary field) variables used only under certain circumstances
[Solution]: This function will be moved inside the class. 
Data Clumps ------------ (blob) data cook often appear together. 
[Solutions]: they then have the base situation, it is together with us, to give them a new class. 
Primitive Obsession ---- (prefer basic types) are keen to use the basic type int, long, String and so on. 
[Solution]: a recurring set of parameters, the plurality of arrays into classes associated bar. 
Switch Statements ------ (switch statement) 
[Resolution]: state / strategy or simply a polymorphism. 
Parallel Inheritance Hierarchies --------------- (Inherited parallel) to increase the ax A subclass of class B type also requires a corresponding increase in bx. 
[Solution]: There should be a class that can get rid of the inheritance. 
Lazy Class ------------------------------------- (verbose class) if he did not work again , fired him. 
[Solution]: these are no longer important classes inside the logic incorporated into the relevant category, delete the old one. 
Speculative Generality ------------------------- (bombastic Futurity) 
[solution]: delete
Message Chains --------------------------------- (message chain) is coupled to excessively bad. 
[Solution]: moving function or functions demolition.
[Solution]: The focus of these temporary variables to a new class of management. 
Most Middle Man ------------------------------------- (intermediaries) are handed over to the agency to handle a. 
[Solution]: inheritance substitute delegate. 
Inappropriate Intimacy ------------------------- (too close) to use the other two classes of private things with each other. 
[Solution]: draw a line break, or merge, or change individual contact. 
Alternative Classes with Different Interfaces - (similar classes, different interfaces) 
[Solution]: rename, move function, or abstract subclass. 
Incomplete Library Class ----------------------- (imperfect library) 
[Solution]: one function package or packages into a new class. 
Data Class ------------- (pure data class) class is very simple, the only common member variables, functions or simple operation. 
[Resolution]: The related operations into the package, reducing the public member variables. 
Refused Bequest -------- (inherited too) many parent class method, only a limited number of subclasses. 
[Solution]: Acting with alternative inheritance. 
Comments --------------- (too many comments) here means the code is too complicated to understand, I had to use comments to explain. 
[Solution]: Avoid comments interpreted code, object code, but the description, background. Good code speak. 
---------------------
Disclaimer: This article is the original article CSDN bloggers "windcao", following the CC 4.0 by-sa copyright agreement, reproduced, please attach the original source link and this statement. 
Original link: https: //blog.csdn.net/windcao/article/details/25773219

  

Guess you like

Origin www.cnblogs.com/qianjinyan/p/11466748.html