Member-only story
Memento Pattern [Swift]
Recently, I came across a post on LinkedIn with a snippet on how to implement the Memento Pattern:
A mere glimpse of this snippet was enough to realize that this implementation is far from being the Memento Pattern.
Through building a simple macOS text editor app, we will figure out:
- What is the Memento Pattern?
- What pattern comes along with it?
- How to implement it properly?
I am a fan of the GoF book, but there is a lovely website with examples in many languages that contains all the patterns from the book and more.
What is the Memento Pattern
The primary purpose of the pattern is to encapsulate an object’s internal state, allowing it to be restored later without exposing its implementation details.
The pattern consists of:
- Memento
- Originator
- Caretaker






