对入参进行赋值
int discount(int inputVal, int quantity, int yearToDate) {if (inputVal > 50) {inputVal -= 2;}
}
重构:用一个临时变量取代该参数
int discount(int inputVal, int quantity, int yearToDate) {int result = inputVal;if (inputVal > 50) {result -= 2;}
}
什么是“对参数赋值”
void method(Object foo) {foo.modifyInSomeWay(); //that's OKfoo = anotherObject; // trouble and despair will follow you.
}