你直接访问一个值域(field),但与值域之间的耦合关系逐渐变得笨拙。
为这个值域建立取值/设值函数(getting/setting methods),并且只以这些函数来访问值域。
private 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;}