Module design_pattern_examples_rust::command
source · Expand description
The Command design pattern example module
The Command pattern is used to encapsulate an operation or command associated with an object so that the command can be applied to the object at a later time.
In this exercise, an undo list is implemented using Commands that associate commands defined in this file with a text object. The commands are applied to the text object in succession then effectively undone.
Accessed through the command_exercise() function.
Modules
- Contains the CommandNoParameters and CommandTwoParameters implementations.
- Contains the ICommand trait that commands implement so they look the same to the main program.
- Contains the CommandTextObject implementation.
Structs
- This struct creates a context around the undo list that the command_exercise() executes within. This gets around the problem of needing a static undo list (or passing the undo list to all functions) as all the methods on this context have ready access to the undo list in the context.
Functions
- Example of using the “Command” pattern.
- An operation to search and replace text in a CommandTextObject.
- An operation to reverse the characters in the given CommandTextObject.