ONJava.com -- The Independent Source for Enterprise Java
oreilly.comSafari Books Online.Conferences.

advertisement

AddThis Social Bookmark Button
Article:
  Form Your Own Design Pattern Study Group
Subject:   solution for undo() method in MacroCommand
Date:   2009-06-07 19:48:37
From:   mkrk
This is with refrence to the solution provided for undo() method in the MacroCommand. The solution provided was :
for (int i = 0; i < commands.length; i++ ) {
commands[i].execute();
}

I believe this solution is wrong. When the undo is called it should undo the last command first
then go all the way to 1st command. It should be


for (int i = commands.length - 1; i >= 0; i-- ) {
commands[i].execute();
}

Is my solution correct or am i missing something.


I would appreciate your response.


Thanks,
RK