Replace Method with Method Object
你有一个大型函数,其中对局部变量的使用使你无法采用“Extract Method”这种重构手法。将这个函数放进一个单独对象中,这样,局部变量就成了对象的字段,然后就可以在同一个对象中将这个大型函数分解为多个小型函数。
//重构前
class Order....
double price(){
double basePrice;
double secondaryPrice;
double thirdaryPrice;
//compute()
......
}
1
2
3
4
5
6
7
8
9
|
|