重构:
在不改变的前提下,提高代码的可理解性,降低其修改成本
The rule of three
添加功能时一并重构
修补错误时一并重构
复审代码时一并重构
composing method
a. Extract method. divide a method into two or more method.
提炼方法, 把能分开,重用的部分单独做一个方法。
b. Inline method. conclude two or method into one method.
和Extract method相反, 概括多个方法成一个, 简化代码.
c. Inline temp. remove temp variable as we can.
d. Replace temp with query. change temp variable 's operation into a method that can be recall some other place
e. Introduce explaining variable. change series of operation into some explaining variable, use clear name
f. Split temporary variable. won't reuse temp variable for many set value operation, it make other confused
g. Remove assignments to parameters.
create a temp variable instead of object, java only use pass by value (参数不要用来赋值, 使用final, 避免对参数赋值)
h. Replace method with method object.
create method object( TestObject _testObject), use 'Extract method', use '_testObject.testMethod()'(method object)
i. Substitute algorithm. improve algorithm
Moving features between objects
a. Move method
b. Move field
c. Extract class.
d. Inline class.
e. Hide delegate. (对method进行加一层封装,使Client不能直接访问method. 简单委托关系)
f. Remove middle man. 和Hide delegate相反, 合理的隐藏程序基于实际系统的变化
g.Introduce foreign method. create new method, set server class entity as argument
ex: Date date = new Date(pro.getYear(), pro.getMonth(), pro.getDay()+1)
----> Date date = nextDay(pro);
staitc Date nextDay(Date pro)
{
return new Date()
}
在不改变的前提下,提高代码的可理解性,降低其修改成本
The rule of three
添加功能时一并重构
修补错误时一并重构
复审代码时一并重构
composing method
a. Extract method. divide a method into two or more method.
提炼方法, 把能分开,重用的部分单独做一个方法。
b. Inline method. conclude two or method into one method.
和Extract method相反, 概括多个方法成一个, 简化代码.
c. Inline temp. remove temp variable as we can.
d. Replace temp with query. change temp variable 's operation into a method that can be recall some other place
e. Introduce explaining variable. change series of operation into some explaining variable, use clear name
f. Split temporary variable. won't reuse temp variable for many set value operation, it make other confused
g. Remove assignments to parameters.
create a temp variable instead of object, java only use pass by value (参数不要用来赋值, 使用final, 避免对参数赋值)
h. Replace method with method object.
create method object( TestObject _testObject), use 'Extract method', use '_testObject.testMethod()'(method object)
i. Substitute algorithm. improve algorithm
Moving features between objects
a. Move method
b. Move field
c. Extract class.
d. Inline class.
e. Hide delegate. (对method进行加一层封装,使Client不能直接访问method. 简单委托关系)
f. Remove middle man. 和Hide delegate相反, 合理的隐藏程序基于实际系统的变化
g.Introduce foreign method. create new method, set server class entity as argument
ex: Date date = new Date(pro.getYear(), pro.getMonth(), pro.getDay()+1)
----> Date date = nextDay(pro);
staitc Date nextDay(Date pro)
{
return new Date()
}