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


This pattern is often used when dealing with frameworks, libraries, and APIs to easily "adapt" the old and existing interfaces to the new requirements of a program.

Roles

The adapter pattern converts the interface of another existing class into an interface waited by the existing clients to allow them to work together. Thanks to this pattern, you can integrate components for which you normally cannot modify the source code and things that often appear with the use of a framework.

Note that you should avoid using this pattern if you already have source code access to the component.

Design

The generic class diagram of the pattern is as follows:

Participants

In the preceding diagram, you can see the four participants of this pattern:

  • ITarget: This introduces the method signature of the object through this interface

  • Client: The client interacts with objects that implement the ITarget interface

  • Adapter: This class implements the method of the ITarget interface and invokes the method...