"Encapsulate a request as an object, thereby letting you parameterize clients with different
requests, queue or log requests, and support undoable operations."
Advantage of Command Pattern
We can support Undo operation using this pattern.
In a football simulation we can track of each moves done by the player.
This is done by converting each action into an object and queuing the object in a list.
Later we can undo the operation by traversing the list.
There is an ICommand interface having Do() and Undo() methods
There is a KickCommand class implementing the above methods
From the main form, whenever the user clicks the football image,
a new KickCommand object is created with the mouse X, Y positions and the football as the argument to the
constructor. These information are required by the KickCommand class to perform Do() and Undo() operations.
After calling the Do() operation the football gets moved on the screen.
Along with that the KickCommand instance is stored in a listbox for logging purpose. On clicking the Undo button the
last command from the listbox is fetched and the Undo() operation is called.
Here the KickCommand encapsulates Do() and Undo() behavior.