《重构:改善既有代码的设计》重构的方法整理

重新组织函数

Extract Method(110) 提炼函数   将两个类的相同部分提取成函数

Inline Method(117) 内联函数

Replace Temp with Query(120) 以查询取代临时变量

Introduce Explaining Variable(124) 引入解释性变量

Split Temporary Variable(128) 分解临时变量

Remove Assignments to Parameters(131) 移除对参数的赋值

Replace Method With Method Object(135) 以函数对象取代函数

Substitute Algorithm(139)  替换算法

 

 在对象之间搬移特性

Move Method(142)  搬移函数

Move Field(142)  搬移字段

Extract Class(149) 提取新的类(当类太庞大的时候)

Inner Class(154) 将类内联化

Hide Delegate(157) 隐藏“委托关系”

Remove Middle Man(160) 移除中间人

Introduce Foreign Method(162) 引入外加函数

Introduce Local Extension(164) 引入本地扩展

 

 重新组织数据

Self Encapsulate Field(171) 自封装字段  (get set)

Replace Data Value with Object(175) 以对象取代数据值

Change Value to Reference(179) 将值对象改为引用对象

Replace Array with Object (186) 将数组替换为对象

Duplicate Observed Data(189) 复制“被监视数据”

Change Unidirectional Association to Bidirectional(197) 将单项关联改为双向关联

Change Bidirectional Association to Unidirectional(200) 将双向关联改为单向关联

Replace Magic Number with Symbolic Constant(204) 用字面常量替换魔法数

Encapsulate Field(206) 封装字段

Encapsulate Collection (208) 封装集合

Replace Record with Data Class(217) 以数据类取代记录

Replace Type Code with Class(218) 以类替代类型码

Replace Type Code with Subclass(223) 以子类替代类型码

Replace Type Code with State/Strategy(227)  以State/Strategy替代类型码

Replace Subclass with Fields(232) 以字段取代子类

 

 简化条件表达式

Decompose Conditional (238) 分解条件表达式
Consolidate Conditional Expression(240) 合并条件表达式
Consolidate Duplicate Conditional Fragments(243) 合并重复的条件片段
Remove Control Flag(245)移除控制标记
Replace Nested Conditional with Guard Clauses(250) 以卫语句取代嵌套条件表达式
Replace Conditional  with Polymorphism(255) 用多态替代条件表达式
Introduce Null Object(267) 引入Null对象
Introduce Assertion(267) 引入断言
 
简化函数调用
Rename Method(273) 函数改名
Add Parameter(275)添加参数
Remove Parameter(277)移除参数
Separate Query from Modifier(279)件查询函数和修改函数分离
Parameterize Method(283)令函数携带参数
Replace Parameter with Explaicit Methods(285)以明确函数取代参数
Preserve Whole Object(288) 保持对象完整性
Replace Parameter with Methods(292)以函数取代参数
Introdeus Parameter Object(295)引入参数对象
Remove Setting Method(300)移除设值函数
Hide Method(303)隐藏函数
Replace Constructor with Factory Method(304)以工厂函数取代构造函数
Encapsulate Downcast (308)封装向下转型
Replace Error Code With Exception(310)以异常取代错误码
Replace Exception with Test(315)以测试取代异常

 

处理概括关系

Pull Up Field(320) 字段上移 将变量提到父类中
Pull Up Method(322) 函数上移 将函数提到父类中
Pull Up Constructor Body(325) 构造函数本体上移

Push Down Method(328)  函数下移 将函数推到子类中

Push Down Field(329) 字段下移  将变量推到子类中

Extract Superclass(330) 提炼子类

Extract Superclass(336) 提炼超类

Extract Interface(341) 提炼接口

Collapse Hierarchy(344)折叠继承关系

Form Template Method(345)  塑造模板函数

Replace Inheritance with Delegation(352)以委托取代继承

Replace Delegation with Inheritance(355)以继承取代委托

 

大型重构

Tease Apart Inheritance(359)梳理并分解继承体系

Convert Procedural Design to Objects(362)将过程化设计转化为对象设计

Separate Domain from Pesentation(368)将领域和表述/显示分离

Extract Hierarchy(375)提炼继承体系

posted @ 2015-07-08 17:02  马小豆包  阅读(320)  评论(0编辑  收藏  举报