1.Self Encapsulate Field

为这个field建立getting/setting method,并且只通过这些函数来访问field.
例:
privte int low,high;
boolean includes(int arg){
    return arg>=low&&arg<=high;
}
重构为:
private int low,high;
boolean includes(int arg){
    return arg>=getLow()&&arg<=getHigh();
}
int getLow(){return low;}
int getHigh(){return high;}

2.Replace Data Value with Object
将一个数据项变成一个对象。
3.Change Value to Reference
将这个实值对象变成一个引用对象。
4.Change Reference to Value
将一个引用对象变成实值对象。
例:
Class Currency{
private String code;
public String getCode()}
    return code;
}
private Currency(String code){
    this.code=code;
}
}
5.Replace Array with Object
以对象替换数组,对于数组中的每个元素,以一个值域表示之。
例:
String[] row=new String[3];
row[0]="Liverpool";
row[1]="15";
重构为:
Performance row=new Performance();
row.setName("Liverpool");
row.setWins("15");
6.Duplicate Observed Data
7.Change Unidirectional Association to Bidirectional
8.Change Bidirectional Association to Unidirectional

只有注册用户登录后才能发表评论。


网站导航:
 

posts - 9, comments - 0, trackbacks - 0, articles - 3

Copyright © 在从未放弃的路上