What is the difference between Chain of Responsibility and Decorator?

Answer

Both Chain of Responsibility and Decorator pass a request along a linked chain of objects, but their intent and behavior differ. In Decorator, every wrapper in the chain always processes the request and forwards it — the chain runs to completion, and behavior is accumulated at each step. In Chain of Responsibility, each handler decides independently whether to handle the request or pass it on — once a handler processes the request, it may stop propagation. Decorator is used to add cumulative features; Chain of Responsibility is used for conditional processing where the appropriate handler is not known in advance. HTTP middleware pipelines blend both: they always pass through (Decorator-like) but can short-circuit on error (Chain-like).