Memento - PowerPoint PPT Presentation

About This Presentation
Title:

Memento

Description:

Kendra Kachelein. Maureen Thomas. Definition. The memento captures and externalizes an object's internal state, so the object ... – PowerPoint PPT presentation

Number of Views:338
Avg rating:3.0/5.0
Slides: 8
Provided by: MAUTH
Category:
Tags: kendra | memento

less

Transcript and Presenter's Notes

Title: Memento


1
Memento
  • Kendra Kachelein
  • Maureen Thomas

2
Definition
  • The memento captures and externalizes an objects
    internal state, so the object can be restored to
    that state later.

3
Applicability
  • Use the Memento pattern when
  • A snapshot of an objects 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
    objects 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
34-55-09
Caretaker
Memento
Originator
6
UML Diagram
Caretaker
Originator
Memento
-State
-State
GetState() SetState()
SetMemento(in Memento) CreateMemento()
Class Example
Security Guard
Owner
Safety Deposit
-State
-State
GetCombo() GiveCombo()
DepositCombination(in Memento) WriteCombination(
)
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
Write a Comment
User Comments (0)
About PowerShow.com