最近在看<重构>这本书,看着看着就迷上了重构.所以打算专门搞一个分类记录一些关于重构的那些事
"重构"是一小步一小步慢慢前进的过程,下面列出书上所写的重构列表,在以后的日子里,我会对应列表,描述每一种重构手法,重构是需要好鼻子的,闻出坏味道,还需要一套规范有效的方式来安全的修改代码.
- Add Parameter (添加参数)
- Change Bidirectional Association to Unidirectional (将双向关联改为单向)
- Change Reference to Value (将引用对象改为值对象)
- Change Unidirectional Association to Bidirectional (将单向关联改为双向)
- Change Value to Reference (将值对象改为引用对象)
- Collapse Hierarchy (合并继承层次)
- Collapse Conditional Expression (合并条件语句)
- Consolidate Duplicate Conditional Fragments (合并重复的条件片段)
- Convert Procedural Design to Objects (将过程式设计转换为面向对象)
- Decompose Conditional (分解条件语句)
- Duplicate Observed Date (重复被观察数据)
- Encapsulate Collection (封装集合)
- Encapsulate Downcast (封装向下转型)
- Encapsulate Field (封装字段)
- Extract Class (提取类)
- Extract Hierarchy (提取继承层次)
- Extract Interface (提取接口)
- Extract Method (提取方法)
- Extract Subclass (提取子类)
- Extract Superclass (提取超类)
- Form Template Method (形成模板方法)
- Hide Delegate (隐藏委托类)
- Hide Method (隐藏方法)
- Inline Class (内联类)
- Inline Method (内联方法)
- Inline Temp (内联临时变量)
- Introduce Assertion (引入断言)
- Introduce Explaining Variable (引入解释性变量)
- Introduce Foreign Method (引入外加方法)
- Introduce Local Extension (引入本地扩展类)
- Introduce Null Object (引入Null对象)
- Introduce Parameter Object (引入参数对象)
- Move Field (移动字段)
- Move Method (移动方法)
- Parameter Method (参数化方法)
- Preserve Whole Object (保持对象完整)
- Pull Up Constructor Body (上移构造器主体)
- Pull Up Field (上移字段)
- Pull Up Method (上移方法)
- Push Down Field (下移字段)
- Push Down Method (下移方法)
- Remove Assignments to Parameters (去除参数赋值)
- Remove Control Flag (去除控制标志)
- Remove Middle Man (去除中间人)
- Remove Parameter (去除参数)
- Remove Setting Method (去除设置方法)
- Rename Method (重命名函数)
- Replace Array with Object (用对象替代数组)
- Replace Conditional with Polymorphism (用多态代替条件语句)
- Replace Constructor with Factory Method (用工厂方法代替构造器)
- Replace Date Value with Object (用对象代替数据值)
- Replace Delegation with Inheritance (用继承代替委托)
- Replace Error Code with Exception (用异常代替错误码)
- Replace Exception with Test (用测试代替异常)
- Replace Inheritance with Delegation (用委托代替继承)
- Replace Magic Number with Symbolic Constant (用字面常量代替魔数)
- Replace Method with Method Object (用方法对象代替方法)
- Replace Nested Conditional with Guard Clauses (用守卫语句代替嵌套条件语句)
- Replace Parameter with Explicit Methods (用显示方法替代参数)
- Replace Parameter with Method (用方法代替参数)
- Replace Record with Data Class (用数据类代替记录)
- Replace Subclass with Fields (用字段代替子类)
- Replace Temp with Query (用查询方法代替临时变量)
- Replace Type Code with Class (用类代替类型码)
- Replace Type Code with State/Strategy (用State/Strategy代替类型码)
- Replace Type Code with Subclasses (用子类代替类型码)
- Self Encapsulate Field (自封装字段)
- Separate Domain from Presentation (将领域逻辑与表现分离)
- Separate Query from Modifier (将查询方法与修改方法分离)
- Split Temporary Variable (分离临时变量)
- Substitute Algorithm (替换算法)
- Tease Apart Inheritance (分解继承层次)
来源:oschina
链接:https://my.oschina.net/u/1250093/blog/164229