72. Computing order price with discounts

The problem proposed here can be solved with the strategy pattern. This design pattern defines a family of algorithms and makes them interchangeable within the family. In this particular problem, both the discounts and the final order price calculators could be implemented based on the strategy pattern. The following diagram describes the hierarchy of discount types and their interchangeable use within the other classes, customer, article, order_line, and order:

The implementation of the discount types is shown here:

struct discount_type{   virtual double discount_percent( double const price, double const ...

Get The Modern C++ Challenge now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.