Command stack is a design patter if we need to support for undo/redo operations.
There are two aspects to this design pattern
ICommand interface where we can define the behaviour of the execution and undo operation and a
CommandStack which is a generic.
- Create an
ICommandinterface with methods
- All undoable/redoable actions should be specified in classes that implement the
- Before the main body of
execute()make sure you have all the information needed to undo
Now we need to create a
- Create a
- Add the following methods to the
- All commands need to be executed through the
execute(ICommand)method of the command stack
- Undo/Redo is also performed through the command stack