Replace Temp with Query

时间:2024-04-25 22:17:52
double GetPrice()
{
int basePrice = _quantity * _itemPrice;
double discountFactor;
if (basePrice > )
{
discountFactor = 0.95;
}
else
{
discountFactor = 0.98;
}
return basePrice * discountFactor;
}

Replace Temp with Query

double GetPrice()
{
return BasePrice() * DiscountFactor();
} int BasePrice()
{
return _quantity * _itemPrice;
} double DiscountFactor()
{
if (BasePrice() > )
{
return 0.95;
}
else
{
return 0.98;
}
}

参考:http://sourcemaking.com/refactoring/replace-temp-with-query