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).
Previous
What are practical use cases for the Memento pattern?
Next
How are GoF patterns used in Java and Python?
More Design Patterns (Gang of Four) Questions
View all →- Intermediate What is the Template Method design pattern?
- Intermediate What is the Visitor design pattern?
- Intermediate What is the difference between Factory Method and Abstract Factory?
- Intermediate When should you NOT use design patterns?
- Intermediate How are the Gang of Four patterns categorized?