Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Memento pattern
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== Structure == === UML class and sequence diagram === [[File:w3sDesign Memento Design Pattern UML.jpg|frame|none|A sample UML class and sequence diagram for the Memento design pattern.<ref>{{cite web|title=The Memento design pattern - Structure and Collaboration|url=http://w3sdesign.com/?gr=b06&ugr=struct|website=w3sDesign.com|access-date=2017-08-12}}</ref>]] In the above UML class diagram, the <code>Caretaker</code> class refers to the <code>Originator</code> class for saving (<code>createMemento()</code>) and restoring (<code>restore(memento)</code>) originator's internal state. <br> The <code>Originator</code> class implements <br> (1) <code>createMemento()</code> by creating and returning a <code>Memento</code> object that stores originator's current internal state and <br> (2) <code>restore(memento)</code> by restoring state from the passed in <code>Memento</code> object. <br> The [[Unified Modeling Language|UML]] sequence diagram shows the run-time interactions: <br> (1) Saving originator's internal state: The <code>Caretaker</code> object calls <code>createMemento()</code> on the <code>Originator</code> object, which creates a <code>Memento</code> object, saves its current internal state (<code>setState()</code>), and returns the <code>Memento</code> to the <code>Caretaker</code>. <br> (2) Restoring originator's internal state: The <code>Caretaker</code> calls <code>restore(memento)</code> on the <code>Originator</code> object and specifies the <code>Memento</code> object that stores the state that should be restored. The <code>Originator</code> gets the state (<code>getState()</code>) from the <code>Memento</code> to set its own state.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)