I'm watching a course about Design Patterns and the example they used for decorator pattern is the Pizza and Toppings example ( you can find the example here as well). Please have a look at the link to understand my issue
What I don't like about this pattern as mentioned in the comments of the link I added is that a topping is not a pizza so why should it inherit the pizza class?
The solution I have in my mind is using an array of PizzaDecorators
objects in a Pizza
object and use that array to add or remove toppings from a pizza.
Isn't this solution much simpler than using the decorator pattern? Why should we consider using the decorator pattern in a situation like this?
Aucun commentaire:
Enregistrer un commentaire