Reputation:
I have the book Design Patterns, by Grady Booch, but I am confused on the difference between the Chain of Responsibility and Command design patterns? Can anyone offer some clarity?
I am trying to figure out which one to use in a mini server system where you can send a command like LOGIN <user:pass>
or ADD_ENTRY <title:description>
or so on, and then I thought I could make a thread where I parse any data coming in and then throw it out to some commandHandler
or something that would look at the command
and the data sent with it, and perform an action on it. It seems like either Chain of Responsibility or Command would work for this, but I am confused on the difference between them.
Can anyone explain?
Upvotes: 3
Views: 6574
Reputation: 697
In chain of responsibility pattern you do not have the chance to undo, save or queue the actions. If you need to do that you have to use command pattern. If you want to execute te operation in a different time than use command pattern. If more than one object can handle a request use chain of responsibility.
Upvotes: 2
Reputation:
Figured it out - command is basically just a command encapsulated in an object. Chain of responsibility is more an object trying to handle something & if not, pass it onto the next one in the 'chain'.
Upvotes: 7