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