坏味道 | 常用重构 |
---|---|
Alternative Classes with Different Interfaces(异曲同工的类) | Rename Method,Move Method |
Comments(过多的注释) | Extract Method, Introduce Assertion |
Data Class(纯稚的数据类) | Move Method, Encapsulate Field,Encapsulate Collection |
Data Clumps(数据泥团) | Extract Class, Introduce Parameter Object,Preserve Whole Object |
Divergent Change(发散式变化) | Extract Class |
Duplicated Code(重复代码) | Extract Method, Extract Class, Pull Up Method, Form Template Method |
Feature Envy(依恋情结) | Move Method, Move Field, Extract Method |
Inappropriate Intimacy (狎昵关系) | Move Methoc,Move Field, Change Bidirectional Association to Unidirectional, Replace Inheritance with Delegation, Hide Delegate |
Incomplete Library Class(不完美的库类) | Introduce Foreign Method, Introduce Local Extension |
Large Class(过大的类) | Extract Class, Extract Subclass, Extract Interface, Replace Data Value with Object |
Lazy Class(冗赘类) | Inline Class, Collapse Hierarchy |
Long Method(过长函数) | Extract Method, Replace Temp With Query, Replace Method with Method Object, Decompose Conditional |
Long Parameter List(过长参数列) | Replace Parameter with Method, Introduce Parameter Object, Preserve Whole Object |
Message Chains(过度耦合的消息链) | Hide Delegate |
Middle Man(中间人) | Remove Middle Man, Inline Method, Replace Delegation with Inheritance |
Parallel Inheritance Hierarchies(平行继承体系) | Move Method,Move Field |
Primitive Obsession(基本类型偏执) | Replace Data Value with Object, Extract Clas,Introduce Parameter Object, Replace Array with Object, Replace Type Code with Class, Replace Type Code with Subclasses, Replace Type Code with State/Strategy |
Refused Bequest(被拒绝的遗赠) | Replace Inheritance with Delegation |
Shotgun Surgery(霞弹式修改) | Move Method,Move Field, Inline Class |
Speculative Generality(夸夸其谈未来性) | Collapse Hierarchy, Inline Class, Remove Parameter, Rename MethocK |
Switch Statements( switch惊悚现身) | Replace Conditional with Polymorphism, Replace Type Code with Subclasses, Replace Type Code with State/Strategy, Replace Parameter with Explicit Methods, Introduce Null Object |
Temporary Field(令人迷惑的暂时字段) | Extract Class, Introduce Null Object |
重构:改善既有代码的设计-坏味道重构方法对应表
坏味道 常用重构 Alternative Classes with Different Interfaces(…