Design Patterns Memento Pattern - Design Patterns

What is Design Pattern Memento Pattern?

Memento pattern is used to restore state of an object to a before state. Memento pattern falls in behavioural pattern group.

Implementation

Memento pattern uses three performer classes. Reminder contains condition of an object to be restored. Originator creates and stores states in reminder objects and Caretaker object is responsible to restore object state from Memento. We have created course Memento, Originator and Caretaker.

MementoPatternDemo, our demo class, will use Caretaker and designer objects to illustrate return of object states.

memento_pattern_uml_diagram


Step 1

Create Memento class.

Memento.java

Step 2

Create Originator class

Originator.java

Step 3

Create Caretaker class

CareTaker.java

Step 4

Use Caretaker and Originator objects.

MementoPatternDemo.java

Step 5

Verify the output.

'

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

Design Patterns Topics