So far, I have not come up with a beautiful solution for implementing UNDO / REDO commands in Java. To work with the command stack, I want to use the “Team” pattern, i.e. you need to implement the "Team" pattern + a couple of classes of commands, and so that from the client class, when calling a particular command, the called commands are added to the history stack, and so that you can roll back the executed commands using the UNDO / REDO command.
More specifically, the problem is that I still don’t understand where it is better to implement the stack of executed commands, while I see 3 options, but I would like to hear the opinions of those who implemented UNDO / REDO in Java.
So my options are: 1. In the client class 2. In the Invoker class (Caller class) 3. In the Receiver class
undomethod to the command class (to the already existingdomethod), when you cancel the command, you will call this method. 2. Otherwise, you can take a snapshot every few actions (depending on the size of the snapshots and the average time for using the commands it can be 10, 100 or 1000), take snapshots too, when you cancel the command to load the last snapshot and apply all of the following to it teams followed him except the last - diraria