函数的行为,完全取决于参数值
public void setValue(final String name, final int value) {
if ("height".equals(name)) {
this.height = value;
return;
}
if ("width".equals(name)) {
this.width = value;
return;
}
Assert.shouldNeverReachHere();
}
重构:针对该参数的每一个可能值,建立一个独立函数
public void setHeight(int arg) {
this.height = arg;
}
public void setWidth(int arg) {
this.width = arg;
}