你有一個(gè)大型函數(shù),其中對(duì)局部變量的使用,使你采用Extract Method(110)。
將這個(gè)函數(shù)放進(jìn)一個(gè)單獨(dú)對(duì)象中,如此一來局部變量就成了對(duì)象內(nèi)的值域(field)。然后你可以在同一個(gè)對(duì)象中將這個(gè)大型函數(shù)分解為數(shù)個(gè)小型函數(shù)。
class Order...
double price() {
double primaryBasePrice;
double secondaryBasePrice;
double tertiaryBasePrice;
// long computation;
...
}
將這個(gè)函數(shù)放進(jìn)一個(gè)單獨(dú)對(duì)象中,如此一來局部變量就成了對(duì)象內(nèi)的值域(field)。然后你可以在同一個(gè)對(duì)象中將這個(gè)大型函數(shù)分解為數(shù)個(gè)小型函數(shù)。
class Order...
double price() {
double primaryBasePrice;
double secondaryBasePrice;
double tertiaryBasePrice;
// long computation;
...
}