Why would I ever use a Chain of Responsibility over a Decorator?

后端 未结 11 1908
[愿得一人]
[愿得一人] 2020-12-04 12:58

I\'m just reading up on the Chain of Responsibility pattern and I\'m having trouble imagining a scenario when I would prefer its use over that of decorator.

What do

11条回答
  •  失恋的感觉
    2020-12-04 13:33

    Well I can think of 2 situations:

    • You don't have a core object, i.e. you don't know what to do with the request after it passed all the layers/filters. (something like an aspect like interceptor chains that don't really care where the request ends).
    • You need to selectively apply some pre or post processing to the request. Not in a general enhancement form as the decorator does. i.e. Filters may or maynot handle a specific request but adding a decorator always enhances your object with some functionality.

    Can't think of any more right now, would love to hear more in this topic.

提交回复
热议问题