Command Pattern Lab 1
Lab Assignment: Implement Additional Commands
You have been given a text editor system that uses the Command pattern to handle cut, copy, and paste operations. Your task is to extend the system by implementing additional commands: undo and redo.
Requirements:
Implement an
UndoCommand
class that represents the command to undo the last executed command in the text editor.Implement a
RedoCommand
class that represents the command to redo the previously undone command in the text editor.Modify the
TextEditor
class to support undo and redo operations. Add necessary methods and attributes to enable tracking and managing the command history for undo and redo.Update the
Toolbar
class to include buttons for undo and redo commands. Create instances ofUndoCommand
andRedoCommand
and associate them with the respective buttons.Test your implementation by simulating user actions, such as cutting, copying, pasting, undoing, and redoing. Verify that the text editor functions correctly and the undo/redo commands work as expected.
Note:
You can assume that the existing classes (
Command
,CutCommand
,CopyCommand
,PasteCommand
,TextEditor
, andToolbar
) are already implemented correctly.You can use the existing code provided in the previous example as a starting point for your implementation.
Submission:
Submit the modified
UndoCommand
,RedoCommand
,TextEditor
, andToolbar
classes as separate files or as part of a single project.Include any additional instructions or notes necessary for running and testing your code.
Good luck with your lab assignment!