The difference between the two patterns is the way in which the request is decoupled.
In the chain of responsibility pattern, the request is passed to potential receivers, whereas the command pattern uses a command object that encapsulates a request.
The following table describes the difference between the chain of responsibility and command patterns:
Chain of responsibility |
Command | |
---|---|---|
Client creates |
Handler objects |
Command objects |
Different kinds of |
Handler classes at different levels |
Command classes and receiver classes |
Client can work with |
Multiple handlers |
Different receivers |
Client calls |
Handler objects |
Receiver objects |
Work is done in |
|
|
Decision based on |
Mask in handlers |
Routing in commands |