Welcome to the CSC Q&A, on our server named in honor of Ada Lovelace. Write great code! Get help and give help!
It is our choices... that show what we truly are, far more than our abilities.

Categories

+10 votes

I am trying to figure out the undo redo feature and just wanted to know if anyone has any tips for it.

asked in CSC305 Fall 2023 by (1 point)

2 Answers

+1 vote
 
Best answer

Nope, mty group did not do it.

answered by (1 point)
selected by
+7 votes

The thing that really tripped me up was the deep cloning. Not only do you have to implement and define the clone method, you have to give the clone its own instances of the mutable fields off of the object you’re cloning, otherwise the snapshot changes along with the original. For example if your object contains a list of cards creatively named cardList, within the clone method you need to say “clone.cardList = cardList;” otherwise it’ll constantly change, and that’s not what you want for undo. Other than that it was pretty straightforward.

answered by (1 point)
+2

Good answer, except you'll want to do:

clone.cardList = new ArrayList(this.cardList);

So that you don't have two references to the same list object...

...