Answered step by step
Verified Expert Solution
Question
1 Approved Answer
[30] 1. Assume that you have opened a modern 'Icecream Bar' in front of the NSU main gate. In your Icecream Bar, different flavors of
[30] 1. Assume that you have opened a modern 'Icecream Bar' in front of the NSU main gate. In your Icecream Bar, different flavors of Ice cream are available along with a range of choices of toppings. Customers can have any flavors with their choice of toppings. You want to build an App for customers to order their flavor and choose toppings. The App should calculate the price according to the ice cream flavor and toppings. Each flavor and toppings have a different unit cost. Initially, you have designed the following class diagram for the App mentioned above. Icecream name: String - hasCandy, boolean - has Sprinkles boolean hasCaramelsauce: boolean + Icecream (...) + getPrice(): double + getHasCandy (): boolean +getHas Sprinkles(): boolean + getHasCaramelsauce(): boolean 4 Chocolatelcecream Vanillacecream getPrice (): double +getPrice(): double Page 1 of 4 13 January 2021 However, this design has the following problems. Price changes in toppings will lead to alternation in the existing code of getPrice(). New toppings will force adding new variables and methods in the Icecream class and changing calculation accordingly. Some toppings may not be appropriate for some ice cream flavors, yet the subclass inherits them. Answer the following questions. a) Apply the Decorator design pattern to solve the problems mentioned above. After applying the Decorator design pattern, draw the class diagram and justify your answer. (20 points) b) Explain how your design satisfies the "Open-Closed Principle". (10 points)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started