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

Comparing the three patterns


Though they seem dissimilar, there are several ways in which we can compare these three patterns:

  • Reusability: All three patterns aim to relieve the developer of implementing a common code repeatedly. Indeed, once the visitor has been implemented, they can be reused with different types of objects without any changes. To facilitate the reuse, you must limit the number of states the visitor needs to be aware of. The interpreter pattern is designed to parse an input where the structure is data driven. The Caretaker and memento classes of the Memento pattern are independent of the data, only the originator should be changed.

  • Working with structure: These patterns are intended to work with structures. Visitor and interpreter require the developer to write traversing codes whereas the memento pattern moves the structure as a whole, relying on the serialization to do the traversing.

  • Objects as argument: In the memento and visitor patterns, objects are passed around...