December 2018
Intermediate to advanced
414 pages
10h 19m
English
Let's imagine you are building an app that manages a shopping list. On the fly, users can add new items, edit items, and also mark them as done (picked up in-store).
Each element of the shopping list can be represented as an Item object:
struct Item {var name: String var done: Bool = false}
Again, we'll use a struct, as for the memento pattern we want all the features of value types such as immutability and copy-on-write.
Then we need to represent the Originator, Memento, and CareTaker objects.
A shopping list is just a list. For the sake of our example, we can implement it in many ways, wrapping the list into a ShoppingList as the OriginatorType, using [Item] as the MementoType, or introducing a third object ...
Read now
Unlock full access