Search code examples
design-patternsmemento

I need a design pattern to provide undo functionality to my program


I need a design pattern to provide undo functionality to my program. I've already used Memento, but I need another for my coursework.


Solution

  • The command pattern is the classic pattern for an undo model.

    basically encapsulate each action in an object (the command) and then make each command able to perform the reverse action. Keep a list of the commands as they are applied and to undo perform the reverse action on the list in reverse.

    an example of using the command pattern for undo is here, although that was simply the first result from a google of 'command pattern for undo'