重构 改善既有代码的设计 第二版 - Bad Smells in Code
- 神秘的名字
- Change Function Declaration
- Rename Variable
- Rename Field
- 重复的代码
- Extract Function
- 代码类似但是不完全相同时Slide Statements
- 如果重复代码位于公共父类的子类中Pull Up Method
- 长函数
- Extract Function
- 使用Replace Temp with Query消除临时变量
- 使用Introduce Parameter Object和Preserve Whole Object缩小参数列表
- 如果还有很多临时变量和参数,就Replace Function with Command
- 使用Decompose Conditional处理条件表达式
- 把switch抽到一个函数
- 如果多个switch语句的切换条件相同,使用Replace Conditional with Polymorphism
- 把循环和循环体的代码抽出,Split Loop
- 长参数列表
- 如果询问一个参数,可以获得另一个参数,就使用Replace Parameter with Query删除第二个参数
- 把很多数据放进一个已经存在的数据结构,Preserve Whole Object
- 如果几个参数总在一起,就组合Introduce Parameter Object
- 如果参数使用标记代表不同的功能,就Remove Flag Argument
- 类是减少参数列表的好方法。特别是多个函数使用的参数相同时, Combine Functions into Class