Performing an undo operation consists of recording the state of
an object before applying changes to its properties and restoring
the previously recorded state of the object after changes are made.
The state of the object must be recorded every time before any change
is applied to the object.
According to this pattern, every modification method of an object
must perform undo recording, i.e. record the current state of the
object before applying any changes. There are two approaches to undo recording:
Complete — All properties of the object are recorded.
This approach is used by automatic undo.
Partial — Only those properties are recorded that are
about to be modified. This approach is used by partial undo.
The state of the object is recorded every time before any of the
object properties are modified. This ensures that the system is ready
at any time if the undo command is invoked.
Note: In some cases, recording the object state
is not required.
When implementing modification methods of a custom object, there is
no need to take this feature into consideration.
Restoring the previous object state is performed by reading the
record from the undo filer and applying modification methods of the
object for parameters being rolled back. During this operation,
recording of the object state is performed for the assumed redo operation.
This is done automatically using the same mechanisms that are used for
undo recording.
Redo operations
When undo recording is implemented, there is no need to make any
additional efforts for redo recording or restoring.
Redo recording is performed automatically every time when an undo operation is performed.
Redo restoring is also done automatically when the redo command is
invoked.