The Memento Pattern: Saving State Without Breaking Encapsulation
ArjanCodes
???????????? Join me in Utrecht next year for an in-person Software Design Retreat! Design, discuss, and learn alongside fellow developers. Join the waitlist: https://arjancodes.com/retreat.
???? Build software that lasts. Join the Software Design Mastery program → https://arjan.codes/mastery.
Undo sounds simple until every change needs its own reverse logic. The Memento pattern offers a different approach: save an object's state and restore it when you need to go back. In this video, I show how to implement the Memento pattern in modern Python using snapshots, dataclasses, protocols, and generics.
???? GitHub Repository: https://git.arjan.codes/2026/memento.
???? Join my Discord server: https://discord.arjan.codes.
⌨️ Keyboard I’m using: https://amzn.to/49YM97v.
???? Chapters:
0:00 Intro
1:20 The Workflow
2:40 Take a Snapshot
6:08 Originator, Memento, and Caretaker
11:02 What Should Be in the Snapshot?
12:03 Undo and Redo
13:12 Memento vs Command
14:01 Beyond Undo
14:35 When Not to Use It
15:07 Final Thoughts
#arjancodes #softwaredesign #python
???? Build software that lasts. Join the Software Design Mastery program → https://arjan.codes/mastery.
Undo sounds simple until every change needs its own reverse logic. The Memento pattern offers a different approach: save an object's state and restore it when you need to go back. In this video, I show how to implement the Memento pattern in modern Python using snapshots, dataclasses, protocols, and generics.
???? GitHub Repository: https://git.arjan.codes/2026/memento.
???? Join my Discord server: https://discord.arjan.codes.
⌨️ Keyboard I’m using: https://amzn.to/49YM97v.
???? Chapters:
0:00 Intro
1:20 The Workflow
2:40 Take a Snapshot
6:08 Originator, Memento, and Caretaker
11:02 What Should Be in the Snapshot?
12:03 Undo and Redo
13:12 Memento vs Command
14:01 Beyond Undo
14:35 When Not to Use It
15:07 Final Thoughts
#arjancodes #softwaredesign #python
0 Comments
No comments yet. Be the first to weigh in.