I read the next intersting discussion: Why would I ever use a Chain of Responsibility over a Decorator?.
My question is why would I ever use a Decorator over a Chain of Responsibility?.
I read the next intersting discussion: Why would I ever use a Chain of Responsibility over a Decorator?.
My question is why would I ever use a Decorator over a Chain of Responsibility?.
Decorator is useful for the exact same reason as the accepted answer:
The fact that you can break the chain at any point differentiates the Chain of Responsibility pattern from the Decorator pattern
With COR, the execution of the request isn't guaranteed. The request might go all the way through the chain without being captured and processed by any link in the chain. In contrast, Decorator forces the request to be handled by all the links in the chain. This is because Decorator wraps the object inside and usually augments functionality by adding some more steps in the method of interest.
We can clearly see that the same feature can be seen as both advantage and disadvantage of the patterns. It depends on the situation and the developer to choose the most appropriate pattern to use.