September 21, 2021

Decorator design pattern: real world use

Decorator design pattern: real world use

I had used majority of the useful patterns except the decorator patten.

When I look on examples like this:

The toppingsdecorator extends a pizza, but when you model it on the real world, the toppings is not a pizza. I can see how the code work but in my mind, inheritance should satisfy the "is a" test, and the toppings decorator shouldnt inherit the pizza, instead it should be part of the composition of pizza.

Does this example give justice to the intent and usefulness of the decorator pattern? Were you able to use the decorator pattern on an actual project? Were you able to get the benefit of the decorator pattern or did it make the code complicated?

submitted by /u/engineerFWSWHW
[link] [comments]