0
Under review

Decorator pattern get specific decorator

Tazio 2 months ago updated by Alexander Shvets 2 months ago 3
So I have a list of decorators, including a Color Decorator. This determines if there is a color shown. Showing this color poses a challenge since I can't get a specific decorator unless adding a getDecorator function to each decorator. Does anyone have some tips on how to make this simpler or straight forward?

Under review

Why do you need Decorators? What do they "decorate"? Do their behaviors stack?

Hey Alexander, I have a small game which houses multiple doors which can be stacked on top of each other like HasZombieDecorator & ColorDecorator. Their behaviour does stack, a simple "bool IsOpen()". Hope this helps

Sorry, I'm still not sure I understand your case. By stacking, I mean that each decorator may affect the outcome of the thing it decorates, and if multiple decorators are stacked together, you get a complex result. For the IsOpen() behavior each decorator would override the true/false result of the previous decorator (which, arguably, makes a little sense).

I could imagine a good case for this if your color decorators stack, and this results into a mixed color from some sort of getColor() method. So, if you have blue, and then yellow, you get the green color in the end (but I'm not sure whether it's what you want). But I have hard time understanding the case where you have color decorators and HasZombie decorator. What is the supposed behavior that is common to both?

If you can explain what you're trying to achieve without mentioning any patterns, that might be a better start of this discussion.