You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Memento Use Case | <aid="udemyVideoLink"href="https://www.udemy.com/course/design-patterns-in-python/learn/lecture/25632770/?referralCode=7493DBBBF97FF2B0D24D"target="_blank"title="Memento Use Case"><imgsrc="/img/udemy_btn_sm.gif"alt="Memento Use Case"/></a> <aid="ytVideoLink"href="https://youtu.be/DFEvyjiUA_A"target="_blank"title="Memento Use Case"><imgsrc="/img/yt_btn_sm.gif"alt="Memento Use Case"/></a> <aid="skillShareVideoLink"href="https://skl.sh/34SM2Xg"target="_blank"title="Memento Use Case"><imgsrc="/img/skillshare_btn_sm.gif"alt="Memento Use Case"/></a>
print(example.value) # now raises an AttributeError
162
170
```
163
-
164
-
## Summary
165
-
166
-
* You don't need to create a new Memento each time an Originators state changes. You can do it only when considered necessary. E.g., an occasional backup to a file.
167
-
168
-
* Mementos can be stored in memory or saved/cached externally. The Caretaker will abstract the complications of storing and retrieving Mementos from the Originator.
169
-
170
-
* Consider the [Command](/command) pattern for fine grained changes to an objects state to manage UNDO/REDO between memento saves. Or even save command history into a Memento that can be later replayed.
171
-
172
-
* In my examples, the whole state is recorded and changed with the Memento. You can use the Memento to record and change partial states instead if required.
173
-
174
-
* When copying state, be aware of shallow/deep copying. In complicated projects, your restore functionality will probably contain a combination of both the [Command](/command) and Memento patterns.
0 commit comments