Download presentation
Presentation is loading. Please wait.
1
Memento Kendra Kachelein Maureen Thomas
2
Definition The memento captures and externalizes an object’s internal state, so the object can be restored to that state later.
3
Applicability Use the Memento pattern when: A snapshot of an object’s state must be saved so that it can be restore to that state later, and A direct interface to obtaining the state would expose implementation details and break the object’s encapsulation
4
Participants There are 3 participants in the Memento pattern: Originator: whose state has to be maintained Memento: stores the state of the Originator object Caretaker: has a handle to the Memento
5
Example Originator Caretaker 34 -55-09 Memento
6
UML Diagram Originator - State +SetMemento(in Memento) +CreateMemento() Memento - State +GetState() +SetState() Caretaker Owner - State +DepositCombination(in Memento) +WriteCombination() Safety Deposit - State +GetCombo() +GiveCombo() Security Guard Class Example:
7
Source Code Implementation public class Owner { private int combination public safetyDeposit getCombo() { return new saftetyDeposit(this); } public void giveCombo(safetyDeposit sd) { combination = sd.combination; }
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.