Action
An Action how a Command is implemented, i.e. the code that runs when a GUI element is pressed
. One action is often shared by multiple GUI Nodes. For example, an 'Undo' button in a ToolBar can use the same Action as an 'Undo' menu item in a Menu.
The DRY
principal (Don't Repeat Yourself).
In a 'traditional' application, DRY
is achieved by calling an 'undo()' method from the onAction
event of the Undo Button, and the Undo MenuItem. However, this means that when we build our scene graphs, we would need to reference the classes that perform the action, and in a large application, this gets messy.
Instead, we define the Actions completely separately from the Commands.
Each Action is part of the Actions class, and each Command is part of the Commands class.