2015-08-13 23:54:40 +02:00
---
layout: pattern
title: Memento
folder: memento
2015-08-15 18:03:05 +02:00
permalink: /patterns/memento/
2015-08-20 21:40:07 +02:00
categories: Behavioral
2015-09-22 18:25:56 +05:30
tags:
- Gang Of Four
2015-08-13 23:54:40 +02:00
---
2016-01-03 21:14:30 +01:00
## Also known as
Token
2015-11-04 21:13:32 +02:00
2016-01-03 21:14:30 +01:00
## Intent
Without violating encapsulation, capture and externalize an
2015-08-13 23:54:40 +02:00
object's internal state so that the object can be restored to this state later.
2019-12-07 20:01:13 +02:00
## Class diagram
2015-08-13 23:54:40 +02:00

2016-01-03 21:14:30 +01:00
## Applicability
Use the Memento pattern when
2015-08-13 23:54:40 +02:00
* a snapshot of an object's state must be saved so that it can be restored to that state later, and
* a direct interface to obtaining the state would expose implementation details and break the object's encapsulation
2016-01-03 21:14:30 +01:00
## Real world examples
2015-08-13 23:54:40 +02:00
2015-08-15 18:03:05 +02:00
* [java.util.Date ](http://docs.oracle.com/javase/8/docs/api/java/util/Date.html )
2015-09-22 18:25:56 +05:30
2016-01-03 21:14:30 +01:00
## Credits
2015-09-22 18:25:56 +05:30
* [Design Patterns: Elements of Reusable Object-Oriented Software ](http://www.amazon.com/Design-Patterns-Elements-Reusable-Object-Oriented/dp/0201633612 )