Replace Temp with Query


double
GetPrice() { int basePrice = _quantity * _itemPrice; double discountFactor; if (basePrice > 1000) { discountFactor = 0.95; } else { discountFactor = 0.98; } return basePrice * discountFactor; }

 

double GetPrice()
{
    return BasePrice() * DiscountFactor();
}

int BasePrice()
{
    return _quantity * _itemPrice;
}

double DiscountFactor()
{
    if (BasePrice() > 1000)
    {
        return 0.95;
    }
    else
    {
        return 0.98;
    }
}

 

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

posted on 2013-12-09 15:02  backslash112  阅读(184)  评论(0编辑  收藏  举报

导航