n real life, sequences aren't easy to control. Once something is set in motion it is difficult to manipulate discrete portions of that movement. And of course, in real life it's impossible to undo a movement. But in programming, sequences aren't so elusive. If you plan correctly, you can define actions and then control them however you like. And one very useful tool in doing so is the Command Behavior pattern.
The Command Behavior pattern is a simple pattern to use. It is especially good at objectifying the concept of an action and an undo action. Converting an action into an object is also a very orderly way to ensure that each behavior converges on a single chunk of code that implements that behavior.
In this article we will investigate the uses of the Command Behavior pattern and we will have a little fun along the way. I added a ball image to a form and implemented commands that represent movements of the ball. Each ball command is placed in a stack permitting you to undo the ball movement or rewind all of the movements. After a bit of tinkering with this code you will see that converting presentation layer (GUI) behaviors into command objects makes it much easier to encapsulate, organize, track, undo, and invoke behaviors, using multiple metaphors, such as buttons and menus.