Download presentation
Presentation is loading. Please wait.
1
Memento Alex “J Lo” Brian C Kiefer
2
Definitions A Memento is a way to create an object that previously existed a tiny repository that saves an object’s state
3
Challenge 19.1 What a few reasons that you might choose to saving a memento in a file rather than as an object?
4
Challenge 19.1 What a few reasons that you might choose to saving a memento in a file rather than as an object? The ability to restore an object’s state has to survive a system crash. You anticipate that the user will exit the system and will want to resume work later. You need to reconstruct an object on another computer.
5
Applications of Memento Undo Your favorite feature Persistent Storage String output
6
Challenge What is the best data structure to use for Undo?
7
Challenge What is the best data structure to use for Undo? Stack
8
Challenge What is the best data structure to use for Undo? Stack How can Java assist you in using Memento for persistent storage?
9
Challenge What is the best data structure to use for Undo? Stack How can Java assist you in using Memento for persistent storage? Serialization XML parsing
10
Challenge 19.5 What are the disadvantages of storing an object as text?
11
Challenge 19.5 What are the disadvantages of storing an object as text? Encapsulation flies out the window. Anyone with a text editor can manipulate the object’s data. For this approach to work, you must be able to parse the text, either using XML parser or writing your own parser for a proprietary format. A textual representation may be much larger than an object serialization with the same information.
12
Challenge 19.5b What are the advantages of storing an object as text?
13
Challenge 19.5b What are the advantages of storing an object as text? Anyone with a text editor can verify an object’s data. Anyone with a text editor can manipulate an object’s data—an advantage in some contexts. It is often easier to pass text between systems than it is to setup interchange with RMI, CORBA, or other protocols.
14
Summary Used for undo and redo Forward and Back buttons Can be used for saving files Via serialization Via strings
15
Questions? Comments? Can’t remember something?
16
Exercise Console browser, without browsing… 1. Implement a back command 2. Implement a forward command 3. Implement saving session to disk See demo program and problem explanation at http://www.alexlo.net/patterns/
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.