Fast undo/redo with memento/command pattern?

前端 未结 2 1098
感动是毒
感动是毒 2020-12-28 23:13

I\'m writing a painting/graphics Java application for a mobile phone (so memory is limited). The application state is essentially three 1000x500 bitmaps (i.e. layers of a pa

2条回答
  •  不知归路
    2020-12-28 23:52

    About your Use the command pattern point: Starting from the initial state and again executing Commands are not needed at all. Each Command class should represent a small user action and should have mechanism to undo what it does in its execute() method, if undo operation is to be supported. We maintain a stack of ***Command objects. When user undoes something, a Command object is popped out from the stack and its undo() method gets called.

    I do not see any motivation for using memento pattern in your case as the undo actions will be in FIFO order. User is not allowed to undo actions as he pleases, I guess.

提交回复
热议问题