Introducing 

Prezi AI.

Your new presentation assistant.

Refine, enhance, and tailor your content, source relevant images, and edit visuals quicker than ever before.

Loading…
Transcript

Definition

Without violating encapsulation, capture and externalize an object's internal state so that the object can be restored to this state later.

Memento Design Pattern

Roll me Back

UML class diagram

Participants

Memento

- Stores internal state of the Originator object.

- Protect against access by objects of other than the originator.

Originator

- Creates a memento containing a snapshot of its current internal state.

- Uses the memento to restore its internal state

Caretaker

- Responsible for the memento's safekeeping

- Never operates on or examines the contents of a memento.

Authors:

Melniciuc Constantin

Moldovan Tatiana

Bîbîlici Victor

Advantages

Conclusion

"A memento is an alternate representation of another object,often in a format suitable for transmission across an external interface."

Matthew Heaney

1. Keeping the saved state external from key object helps to maintain cohesion.

2. Keeps the key object's data encapsulated.

3. Provides easy-to-implement recovery capability.

Disadvantages

1. Saving and restoring state may be time consuming.

2. In Java consider using serialization to save a system's state.

3. It exposes the internal structure of your object.

4. It enables the other object to arbitrarily change the state of your object.

How it works

1. Identify the roles of "care taker" and "originator".

2. Originator creates a Memento and copies its state to that Memento.

3. Caretaker holds on to(but cannot peek into) the Memento.

4. Caretaker knows when to rollback the originator.

5. Originator reinstantes itself using the saved state in that Memento.

Learn more about creating dynamic, engaging presentations with Prezi