重新组织函数
Extract Method
Inline Method
Inline Temp
Replace Temp with Query
Introducing Explaining Variable
Split Temporary Variable
Remove Assignments to Parameters
Replace Method with Method Object
Substitute Algorithm
在对象间搬移特性
Move Method
Move Field
Extract Class
Inline Class
Hide Delegate
解决Message Chain坏味道
Remove Middle Man
Hide Delegate的反向行为
Introduce Foreign Method
Introduce Local Extension
重新组织数据
Self Encapsulate Field
Replace Data Value with Object
Change Value to Reference
希望将许多彼此相等的实例,替换成同一个对象
Change Reference to Value
很小而不可变的引用对象,不再合适
Replace Array with Object
Duplicate Observed Data
Change Unidirectional Association to Bidirectional
Change Bidirectional Association to Unidirectional
Replace Magic Number with Symbolic Constant
Encapsulate Field
Encapsulate Collection
让获取函数返回集合的副本,并且提供添加/移除元素的函数
Replace Record with Data Class
Replace Type Code with Class
user defined type替代primitive type
Replace Type Code with Subclasses
在自身上发展继承体系
首先需要Replace Constructor with Factory Method
Replace Type Code with State/Strategy
类型可能会变化,或者自身无法发展继承体系。
Replace Subclass with Fields
子类行为过于简单,已经没有存在必要
简化条件表达式
Decompose Conditional
Consolidate Conditional Expression
Consolidate Duplicate Conditional Fragments
Remove Control Flag
用break和continue等替代flag
Replace Nested Conditional with Guard Clauses
如果条件表达式中只有一种是正常情况,异常情况可以作为卫语句
Replace Conditional with Polymorphism
是Replace Type Code的继续工作
Introduce Null Object
Introduce Assertion
某段代码需要对程序状态做出假设,以断言明确表示这种假设
简化函数调用
Rename Method
Add Parameter
Remove Parameter
Separate Query from Modifier
明确表示出“有副作用”和“无副作用”函数之间的区别
Parameterize Method
Replace Parameter with Explicit Methods
一个函数,其中完全取决于参数而采取不同行为
针对参数的每一个可能值,建立一个独立函数
Preserve Whole Object
参数
Replace Parameter with Methods
以方法取代参数
Introduce Parameter Object
Remove Setting Methods
Hide Method
private
Replace Constructor with Factory Method
希望在创建对象时不仅仅做简单的构建动作
Replace Type Code时就用到了,根据Type Code生成不同子类的对象
Encapsulate Downcast
Replace Error Code with Exception
利用Exception来显示表明错误
Replace Exception with Test
对Exception的滥用
处理概括关系
Pull Up Field
Pull Up Method
Pull Up Constructor Body
各子类构造函数中有相似部分
Push Down Method
Push Down Field
Extract Subclass
Extract Superclass
两个类有相似特性
Extract Interface
若干客户使用类接口中的同一子集
两个类的接口有相同部分
Collapse Hierarchy
超类和子类无太大区别
Form Template Method
相同的算法结构
Replace Inheritance with Delegation
子类只使用超类接口中的一部分
或者根本不想要超类继承而来的数据
Replace Delegation with Inheritance
两个类之间使用委托关系,并经常为整个接口编写简单的委托函数
大型重构
Tease Apart Inheritance
某个继承体系同时承担着两项责任
建立两个继承体系,并通过委托关系让其中一个可以调用另外一个
Convert Procedural Design to Objects
将数据记录变成对象
将大块的行为分为小块,并将行为移入相关对象之中
Separate Domain from Presentation
GUI类中包含了领域逻辑
将领域逻辑独立出来,为它们建立独立的领域类
Extract Hierarchy
某个类做了太多工作,其中一部分工作是以大量条件表达式完成的
建立继承体系,以一个子类表示一种特殊情况
等等