Refactoring - Replace Temp with Query
Motivation: You are using a temporary variable to hold the result of an expression.
public double GetDiscountedPrice()
{
double basePrice = _quantity * _itemPrice;
double discountFactor;
if (basePrice > 1000) discountFactor = 0.95;
else discountFactor = 0.98;
return basePrice * discountFactor;
}
Refactor as:
public double GetDiscountedPrice()
{
return BasePrice() * DiscountFactor();
}
private double BasePrice()
{
return _quantity * _itemPrice;
}
private double DiscountFactor()
{
if (BasePrice() > 1000) return 0.95;
else return 0.98;
}
Comments
Post a Comment