1 / 7

Using the Command Pattern to Simplify Undo and Redo

Using the Command Pattern to Simplify Undo and Redo . Move interface. Abstract class with 2 abstract methods: Execute: apply the move Undo: undo the move Implementation for each type of move Encapsulate the logic of applying a move in the entities. Abstract MoveController.

skyla
Télécharger la présentation

Using the Command Pattern to Simplify Undo and Redo

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Using the Command Pattern to Simplify Undo and Redo

  2. Move interface Abstract class with 2 abstract methods: Execute: apply the move Undo: undo the move Implementation for each type of move Encapsulate the logic of applying a move in the entities

  3. AbstractMoveController Also abstract class with one abstract method: execute() Each one is responsible for converting GUI locations into entity objects Each one creates the appropriate type Move

  4. TypeOfMovementController TypeOfMovementController determines the type of movement done on the GUI It instantiates an instance of the MoveController The MoveControllerexecute the move on the entities and stores the Move object in the MoveHistory

  5. MoveHistory, UndoController, and RedoController UndoController and RedoController rely on MoveHisory to implement undo and redo in the entities MoveHistory uses the undo() and execute() methods of the Moveobjects to do the actual manipulation of entities MoveHistory returns the Move to the UndoControlleror RedoController UndoController and RedoController use the contents of the Move to update the GUI

  6. Benefits • Single location stores the logic of how to apply and undo a move. • MoveHistory does not need to know what the moves that it is storing are or how to apply a move. • MoveController does not need to contain any logic of how to update entity objects.

  7. Weaknesses • Even though the MoveController needs to have all the objects that are used to apply the move, it has to call an external method to do it. • MoveController still has four instances, one for each type move, and cannot fully abstract the type of movement. • Chains of moves have intermediate locations stored twice, once as the end point of one move and again as the starting point of another. • Requires the supporting method TypeOfMovementController to determine the move.

More Related