Use cases of the Command design pattern
It is better to apply the command in the following cases:
- When you need to keep a history of requests. An invoker can save command instances after calling its
execute method to implement history functionality somewhere.
- When you need to implement callback functionality. If you pass to the invoker two objects one after another, the second object will be a callback for the first.
- When you need requests to be handled at variant times or in variant orders. To achieve this, you can pass the command objects to different invokers, which are invoked by different conditions.
- When the invoker should be decoupled from the object handling the invocation.
- When you need to implement the undo functionality. To achieve this, ...