-
Notifications
You must be signed in to change notification settings - Fork 1.7k
User should be allowed to Undo and Redo certain commands #390
Comments
@Zhiyuan-Amos do some research on various approaches to implementing an undo command and share them here. Some relevant points:
Adding @MightyCupcakes @PierceAndy as they were interested in the undo command IIRC. |
|
I feel that an interface could be used instead of an abstract class, as it serves as a "contract" to say that this command is capable of being "undo"ed. Also redo after undo would be re-executing the same command again, so don't think we need a
This can take up quite a big portion of the memory if the AddressBook is of a certain size (e.g. 100 over entries...) But you are right in that there will be quite a few corner cases that we need to consider for selective undo, and since we want to keep level 4 simple yet functional, we can probably do selective undo in level 5 instead. |
Also possible. Rationale for using an abstract class is because
Yup you are right; each command doesn't need to implement |
@Zhiyuan-Amos as discussed, you can spend some time to do more research and experimentation and recommend an approach. There is no need to implement extra things like 'selective undo' or 'undo GUI mutations'. I mentioned them just so that we can consider them in our decision, all other things being equal. There is no need to complicate our design just to accommodate such 'unlikely' features. |
All commands that mutate the state of the AddressBook should be On the other hand, a
I have thought about this but it is actually quite easy to implement. All successfully executed commands is placed in a stack held by the |
I'm not sure whether we should place it in the
This can be solved by storing additional values in the 'Undoable' commands (for e.g in |
Special because it takes up a huge chunk of memory? Otherwise it is possible to reverse the deletion of the entire address book... |
User is unable to undo and redo the actions he / she has made. User is unable to recover from mistakes. For example, if the user accidentally enters the clear command, he / she will lose all the data in AddressBook, and there are no ways to retrieve the data back. Let's implement UndoCommand and RedoCommand so that the user can recover from his / her mistakes.
in the event where the user may have accidentally entered an undesirable command, in which user is able to reverse the command easily.
I'm not sure whether this is the right place to discuss the implementation of Undo and Redo.
Reference: Command Pattern (refer to the section titled Undo and Redo)
Creating an abstract class
ReversibleCommand
which extendsCommand
.ReversibleCommand
contains an abstract methodundo
and a default methodredo
(which basically callsexecute
). Only commands that changes the model will inherit fromReversibleCommand
i.e Add, Edit, Delete, Clear.From the reference above, we can implement a
historyArray
inLogicManager
, which upon every command execution, pushes the command into thehistoryArray
. Each command will now have to store slightly more information:Upon executing
AddCommand
,AddCommand
also has to store the index of person added on the list. When executing undo, executeDeleteCommand
at the index.Upon executing
DeleteCommand
, store the details of the person being deleted. When executing undo, execute the equivalentAddCommand
. However, over here we have to support adding at a particular index i.e we cannot solely executeAddCommand
(new MoveCommand?). It's not necessary to have to executeAddCommand
as well, since I think we can just manipulate the model to add the person at a particular index.Upon executing
ClearCommand
, store the entire model. When executing undo, restore the entire model.Upon executing
EditCommand
, store the original information of the person being edited. When executing undo, executeEditCommand
using the original information.Then, we have an index to point to the
historyArray
so we know which command to undo / redo next. An alternative implementation is to useundoStack
andredoStack
.The text was updated successfully, but these errors were encountered: