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 chain of responsibility pattern


When you write an application, it may be that an event generated by an object needs to be handled by another object. You may also want the handle to be inaccessible by another object.

Roles

In this section, you will notice that the chain of responsibility pattern creates a chain of objects in such a way that if an object of this chain cannot handle the request, it sends the request to the next object, the successor, until one of them can handle the request.

This pattern allows an object to send a request without knowing which object will receive and handle it. The request is sent from one object to another, making them parts of a chain. Each object of this chain can handle the request, pass it to its successor, or do both.

You may want to use this pattern when:

  • You want to decouple the sender of a request to its receiver, allowing other objects to handle the request too

  • Objects that can handle the request are part of a chain of work, the request passes from...