Decorator Pattern Lab
Objective: Extend the CoffeeShop application to include a new condiment, WhippedCream
. WhippedCream
should be a decorator that adds an extra cost to the Beverage
it decorates and appends ", Whipped Cream" to its description.
Task 1: Implement the WhippedCream
class
The WhippedCream
class should implement the CondimentDecorator
interface and take a Beverage
object in its constructor. In the getDescription
method, it should call getDescription
on the Beverage
object and append ", Whipped Cream". In the getCost
method, it should call getCost
on the Beverage
object and add the cost of the whipped cream (50 cents)
Task 2: Extend the client application
Modify the CoffeeShop
application to include a WhippedCream
object in the list of CondimentDecorator
objects. Print the description and cost.