Refactoring a baggage price calculator
We’ll start by examining a baggage price calculator used by the staff of Cloudy Skies Airline during baggage checks to determine the amount an individual customer must pay.
The rules for baggage pricing are as follows:
- All carry-on baggage costs $30 per bag
- The first checked bag a passenger checks costs $40
- Each subsequent checked bag costs $50
- If the travel occurs during the holidays, a 10% surcharge is applied
This code lives in a C# BaggageCalculator
class that we’ll review in a few blocks of code, starting with the class definition, field, and full property:
BaggageCalculator.cs:
public class BaggageCalculator { private decimal holidayFeePercent = 0.1M; public decimal HolidayFeePercent { get { return holidayFeePercent; } set { holidayFeePercent = value; } }
This is a simple class with an older style of property...