Swift 2 Design Patterns
eBook - ePub

Swift 2 Design Patterns

Julien Lange

Share book
  1. 224 pages
  2. English
  3. ePUB (mobile friendly)
  4. Available on iOS & Android
eBook - ePub

Swift 2 Design Patterns

Julien Lange

Book details
Book preview
Table of contents
Citations

About This Book

Build robust and scalable iOS and Mac OS X game applications

About This Book

  • Learn to use and implement the 23 Gang of Four design patterns using Swift 2
  • Design and architect your code for Swift application development
  • Understand the role, generic UML design, and participants in the class diagram of the pattern by implementing them in a step-by-step approach

Who This Book Is For

This book is intended for competent Swift developers who want to apply enduring design patterns with Swift to structure and scale their application code.

What You Will Learn

  • Choose the appropriate pattern depending on the problem to be solved
  • Understand the generic class diagram of each of the 23 GoF patterns and how each object participates in the pattern
  • Use Swift to implement these patterns even though the language doesn't provide all of the object-oriented programming concepts such as abstract class, interface, and so on
  • Architect your software to avoid the overuse of memory, time spent on calculations, or high network traffic
  • Find the best way to organize your code to make it more secure from the outside world
  • Prepare your code to make it more flexible when the consumer changes or the third-party component hidden code changes
  • Structure your code to change the algorithm to apply at runtime
  • Deliver Flyweight responsibility to your objects

In Detail

Swift is a multi-paradigm language. It has expressive features familiar to those used to work with modern functional languages, while also keeping the object-oriented features of Objective-C. It remains compatible with Apple's legacy codes and frameworks. A design pattern systematically names, motivates, and explains a general design that addresses a recurring design problem in object-oriented systems. It describes the problem, the solution, when to apply the solution, and its consequences. It also gives implementation hints and examples. Knowledge about design patterns is also one of the best ways to make you different compared to other low-level developers.

This book shows you how to use Swift 2 to learn about 23 Gang of Four (GoF) design patterns, and is organized into three categories. The book will present you the five creational patterns, followed by the seven structural patterns, and finishing with the 11 behavioral patterns as defined by the GoF. Each chapter will introduce the pattern by defining its role, which common problems the pattern should be used for, its generic UML representation, how each objects presented in the class diagram participate in the pattern, and what the role of each of these objects is. The book then presents you with a concrete case as an illustration that will be used to implement the pattern using Swift.

Style and approach

A step-by-step tutorial completed with screenshots and code highlights wherever necessary. Each chapter discusses one or more patterns with its definitions and a simple-to-follow illustration case using a playground or XCText project to implement it with Swift.

Frequently asked questions

How do I cancel my subscription?
Simply head over to the account section in settings and click on “Cancel Subscription” - it’s as simple as that. After you cancel, your membership will stay active for the remainder of the time you’ve paid for. Learn more here.
Can/how do I download books?
At the moment all of our mobile-responsive ePub books are available to download via the app. Most of our PDFs are also available to download and we're working on making the final remaining ones downloadable now. Learn more here.
What is the difference between the pricing plans?
Both plans give you full access to the library and all of Perlego’s features. The only differences are the price and subscription period: With the annual plan you’ll save around 30% compared to 12 months on the monthly plan.
What is Perlego?
We are an online textbook subscription service, where you can get access to an entire online library for less than the price of a single book per month. With over 1 million books across 1000+ topics, we’ve got you covered! Learn more here.
Do you support text-to-speech?
Look out for the read-aloud symbol on your next book to see if you can listen to it. The read-aloud tool reads text aloud for you, highlighting the text as it is being read. You can pause it, speed it up and slow it down. Learn more here.
Is Swift 2 Design Patterns an online PDF/ePUB?
Yes, you can access Swift 2 Design Patterns by Julien Lange in PDF and/or ePUB format, as well as other popular books in Computer Science & Application Development. We have over one million books available in our catalogue for you to explore.

Information

Year
2015
ISBN
9781785887611
Edition
1

Swift 2 Design Patterns


Table of Contents

Swift 2 Design Patterns
Credits
About the Author
About the Reviewers
www.PacktPub.com
Support files, eBooks, discount offers, and more
Why subscribe?
Free access for Packt account holders
Preface
What this book covers
What you need for this book
Who this book is for
Conventions
Reader feedback
Customer support
Downloading the example code
Downloading the color images of this book
Errata
Piracy
eBooks, discount offers, and more
Questions
1. Creational Patterns
The prototype pattern
Roles
Design
Participants
Collaborations
Illustration
Implementation
Usage
The factory method pattern
Roles
Design
Participants
Illustration
Implementation
Usage
The singleton pattern
Roles
Design
Participants
Collaborations
Illustration
Implementation
Usage
The abstract factory pattern
Roles
Design
Participants
Collaborations
Illustration
Implementation
Usage
The builder pattern
Roles
Design
Participants
Collaborations
Illustration
Implementation
Usage
Implementation using closures
Summary
2. Structural Patterns – Decorator, Proxy, and Bridge
Static and dynamic composition
The decorator pattern
Roles
Design
Participants
Collaboration
Sample
Implementation
Usage
The proxy pattern
Roles
Design
Participants
Collaboration
Illustration
Implementation
Usage
The bridge pattern
Roles
Design
Participants
Collaboration
Illustration
Implementation
Usage
Summary
3. Structural Patterns – Composite and Flyweight
The composite pattern
Roles
Design
Participants
Collaboration
Illustration
Implementation
Implementation of the VODComponent
Implementation of the VODItem leaf
Implementation of the VODCategory composite
Usage
The flyweight pattern
Roles
Design
Participants
Collaboration
Illustration
Implementation
Usage
Performance results
Summary
4. Structural Patterns – Adapter and Facade
The adapter pattern
Roles
Design
Participants
Collaboration
Illustration
Implementing our first prototype
Implementation
Implementation of our adaptees
Implementation of the SamSingAdapter class
Implementation of the PearAdapter class
The facade pattern
Roles
Design
Participants
Collaboration
Illustration
Implementation of the facade
Summary
5. Behavioral Patterns – Strategy, State, and Template Method
The strategy pattern
Roles
Design
Participants
Collaboration
Illustration
Implementation
The state pattern
Role
Design
Participants
Collaboration
Illustration
Implementation
The template method
Role
Design
Participants
Collaboration
Illustration
Implementation
Summary
6. Behavioral Patterns – Chain of Responsibility and Command
The chain of responsibility pattern
Roles
Design
Participants
Collaboration
Illustration
Implementation
The command pattern
Roles
Design
Participants
Collaboration
Illustration
Implementation
Comparison between the chain of responsibility and command patterns
Summary
7. Behavioral Patterns – Iterator, Mediator, and Observer
The iterator pattern
Roles
Design
Participants
Collaboration
Illustration
Implementation
The mediator pattern
Roles
Design
Participants
Collaboration
Illustration
Implementation
The observer pattern
Roles
Design
Participants
Collaboration
Illustration
Implementation
Summary
8. Behavioral Patterns – Visitor, Interpreter, and Memento
The visitor pattern
Roles
Design
Participants
Collaboration
Illustration
Implementation
The interpreter pattern
Roles
Design
Participants
Collaboration
Illustration
Implementation
The memento pattern
Roles
Design
Participants
Collaboration
Illustration
Implementation
Comparing the three patterns
Summary
Index

Swift 2 Design Patterns

Copyright © 2015 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.
First published: October 2015
Production reference: 1231015
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham B3 2PB, UK.
ISBN 978-1-78588-761-1
www.packtpub.com

Credits

Author
Julien Lange
Reviewers
Vladimir Pouzanov
Victor Sigler
Ye Xiaodong
Acquisition Editor
Tushar Gupta
Content Development Editor
Shali Deeraj
Technical Editor
Saurabh Malhotra
Copy Editors
Rashmi Sawant
Sneha Singh
Project Coordinator
Kinjal Bari
Proofreader
Safis Editing
Indexer
Hemangini Bari
Graphics
Disha Haria
Jason Monteiro
Abhinash Sahu
Production Coordinator
Komal Ramchandani
Cover Work
Komal Ramchandani

About the Author

Julien Lange is a 34-year-old IT expe...

Table of contents