1 / 16

Memento

Memento. Alex “J Lo” Brian C Kiefer. Definitions. A Memento is a way to create an object that previously existed a tiny repository that saves an object’s state. Challenge 19.1. What a few reasons that you might choose to saving a memento in a file rather than as an object?. Challenge 19.1.

garson
Télécharger la présentation

Memento

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. 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. Can’t remember something? Questions? Comments?

  16. Exercise Console browser, without browsing… • Implement a back command • Implement a forward command • Implement saving session to disk See demo program and problem explanation at http://www.alexlo.net/patterns/

More Related