Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I'm a fan of verbosity here:</p> <pre><code>DiscountThresholdInSeconds </code></pre> <p><strong>Based on your edit #1:</strong></p> <p>If you have a class "Ticket," I would simply give it a collection of discounts:</p> <pre> <code> public class Ticket { private List &lt;Discount&gt; m_availableDiscounts = new List&lt;Discount&gt;(); private decimal m_basePrice = 0m; private DateTime m_showTime; public Ticket(DateTime showTime) { m_showTime = showTime; } public List&lt;Discount&gt; Discounts { get { return m_availableDiscounts; } } public decimal BasePrice { get { return m_basePrice; } set { m_basePrice = value; } } public DateTime ShowTime { get { return m_showTime; } } public decimal CalculatePrice(int quantity) { //Apply discounts here... } } public class Discount { private int m_thresholdInSeconds = 0; private decimal m_percentOff = 0m; private decimal m_flatAmountOff = 0m; public Discount(int thresholdInSeconds, decimal percentOff, decimal flatAmountOff) { m_thresholdInSeconds = thresholdInSeconds; m_percentOff = percentOff; m_flatAmountOff = flatAmountOff; } public int ThresholdInSeconds { get { return m_thresholdInSeconds; } } public decimal PercentOff { get { return m_percentOff; } } public decimal FlatAmountOff { get { return m_flatAmountOff; } } } </code> </pre> <p><strong>Edit #2 based on question Edit #2</strong></p> <p>The difference between what you have listed and the code I provided is that yours only allows for two distinct discount periods while mine will support the tiered model. If we really are talking about tickets here, think about it like a timeline:</p> <p>Now-------------------------------------------------------------------------ShowTime</p> <p>At any time in that period, you may have surpassed a threshold (checkpoint, boundary, whatever) that qualifies you for a discount.</p> <p>------------|------Now------------|------------------|---------------|---|---ShowTime</p> <p>Since ShowTime is the stable piece of information in this time line, you need to capture "distance" from showtime and the applicable discount. The "distance" from ShowTime is the threshold that gets crossed.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload