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 mediator pattern


The mediator pattern is used to reduce the coupling between classes that communicate with each other.

Roles

This pattern constructs an object, which manages the communication between two or more classes.

These classes don't know each other's implementation. The message is sent from the class to the mediator object.

The mediator pattern defines an object that encapsulates how a set of objects will communicate with each other. Mediator promotes loose coupling by keeping objects from referring to each other explicitly and it also lets you vary their interaction independently.

The mediator is an intermediary used to decouple many peers. This pattern can be used when we want to design reusable components but dependencies between the potentially reusable pieces demonstrate the "spaghetti code" phenomenon.

Design

The following class diagram presents the generic structure of the mediator pattern:

Participants

In this pattern, we find the following participants:

  • Mediator: This defines...