Book Image

Swift 2 Design Patterns

By : Julien Lange
Book Image

Swift 2 Design Patterns

By: Julien Lange

Overview of this book

Table of Contents (15 chapters)
Swift 2 Design Patterns
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

The memento pattern


The memento pattern will be the last pattern that we will discover together. You will see that this pattern is really interesting to work with and has many uses.

Roles

The role of the memento pattern is to capture an object's internal state and save it externally so that it can be restored later without breaking the encapsulation of this object.

Design

The generic UML class diagram is defined as the following:

Participants

The following are the participants of the memento pattern:

  • Memento: This is the class for the objects that saved the internal states of origin objects (or part of this state), such as the introduction of the fact that the saving of a state can be made independent of the object itself. The memento has two interfaces:

    • A complete interface for Originator objects that permit access to everything that needs to be saved or restored

    • A narrow interface to the caretaker that can keep and pass on the memento references, but no more

  • Originator: This is the object class...