...
/Solution: Apply Flexible Discounts for Marketing Campaigns
Solution: Apply Flexible Discounts for Marketing Campaigns
Implement self-contained discount strategies and delegate discount calculation through a configurable DiscountService context.
We'll cover the following...
We'll cover the following...
Solution explanation
Lines 2–22: We define three discount strategies:
FlatDiscount,PercentageDiscount, andLoyaltyDiscount.Each strategy encapsulates a distinct pricing rule through a
.calculate()method.FlatDiscountapplies a fixed numeric deduction.PercentageDiscountmultiplies the subtotal to simulate a percentage-based reduction.LoyaltyDiscountsimulates a loyalty-tier reduction, representing customer-specific logic.
Lines 25–38: ...