Command Pattern for undo/redo in paint application
问题 I would like to implement undo/redo in a small paint application. It seems the Command Pattern fits the use nicely, but I am unsure how to best implement it. As I understand the pattern, it is necessary to include in each command: The details of the paint operation for purposes of redo (e.g. Line -> start & end points, free form line -> GeneralPath ) The state of the component prior to the change for undo. In this case, that will be a small snapshot image of the area affected by the command.