From the course: C++ Design Patterns: Structural

Unlock the full course today

Join today to access over 24,900 courses taught by industry experts.

Solution: Pizza toppings

Solution: Pizza toppings - C++ Tutorial

From the course: C++ Design Patterns: Structural

Solution: Pizza toppings

(upbeat music) - [Narrator] Welcome back. How did you do? Now let's take a look at the solution I have come up with for this design challenge. As discussed in the previous video, we need to design a decorator based solution that allows customers to order pizzas with additional toppings and calculate the final price accordingly. First, I created a base topping decorator class that wraps the pizza class. The topping decorator class takes an appointer to the pizza object and provides implementations of the description and price methods. Note that I use unique pointers instead of raw pointers. The constructor takes ownership of the pointer using the move function. The description and the price methods delegate the call to the wrapped pizza object. The actual decoration of the pizza is done by the concrete topping decorator classes that extend topping decorator. The following is the design for the mushroom decorator…

Contents