Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 534472a

Browse filesBrowse files
committed
update Memento pattern
1 parent 516e104 commit 534472a
Copy full SHA for 534472a

File tree

1 file changed

+22
-14
lines changed
Filter options

1 file changed

+22
-14
lines changed

‎BehavioralPatterns/Memento/README.md

Copy file name to clipboardExpand all lines: BehavioralPatterns/Memento/README.md
+22-14Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,6 @@ Only the originator that created a memento is allowed to access it.
1717

1818
A client (caretaker) can request a memento from the originator to save the internal state. It can also pass a memento back to the originator to restore to a previous state.
1919

20-
## Benefits
21-
22-
* Does not violate the originator's encapsulation.
23-
* Keeping the saved state external from the originator helps to maintain cohesion.
24-
* Provides easy-to-implement recovery capability.
25-
26-
## Drawbacks
27-
28-
* Saving and restoring state can be time consuming.
29-
* It may require lots of memory if clients create mementors too often.
30-
* Clients should track the originator's lifecycle in order to destroy obsolete mementos.
31-
3220
## Common Structure
3321

3422
![Common structure of memento pattern](https://upload.wikimedia.org/wikipedia/commons/3/38/W3sDesign_Memento_Design_Pattern_UML.jpg)
@@ -44,7 +32,21 @@ A client (caretaker) can request a memento from the originator to save the inter
4432
* never operates on or examines the contents of a memento
4533
* When originator has to go back in history, the caretaker passes the last memento to the originator's restoration method.
4634

47-
_[Source: http://www.dofactory.com/net/memento-design-pattern]_
35+
## Collaboration
36+
37+
* Mementos are passive. Only the originator that created a memento will assign or retrieve its state.
38+
39+
## Benefits
40+
41+
* Does not violate the originator's encapsulation.
42+
* Keeping the saved state external from the originator helps to maintain cohesion.
43+
* Provides easy-to-implement recovery capability.
44+
45+
## Drawbacks
46+
47+
* Saving and restoring state can be time consuming.
48+
* It may require lots of memory if clients create mementors too often.
49+
* Clients should track the originator's lifecycle in order to destroy obsolete mementos.
4850

4951
## Example
5052

@@ -113,4 +115,10 @@ State is set to State 3
113115
Saving state to Memento
114116
State is set to State 4
115117
State is restored from Memento: State 2
116-
```
118+
```
119+
120+
## Relations with Other Patterns
121+
122+
- **Command** can use Mementos to maintain state for undoable operations.
123+
124+
- **Iterator** - Mementos can be used for iteration as described earlier.

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.