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 template method


The template method pattern is a simple pattern used when you need a general behavior but where the details of the algorithm must be specific to subclasses.

Role

The template method pattern isolates various parts of an algorithm. The algorithm skeleton is defined in an abstract class where some steps of the algorithm are delegated to its subclasses and some others are fixed in the abstract class itself and cannot be overridden in subclasses.

Design

The following diagram describes the generic structure of the template method:

Participants

The participants of this pattern are as follows:

  • The AbstractClass, which defines the template method, and the signature of the sub parts of the algorithm are invoked by the template method.

  • The ConcreteClass implements abstract methods used by the template method of the AbstractClass. It is possible to have several concrete classes.

Collaboration

The algorithm defined in the template method is called TemplateMethod() in the generic UML class diagram...