Swift 2 Design Patterns

Swift 2 Design Patterns

Language: English

Pages: 224

ISBN: 1785887610

Format: PDF / Kindle (mobi) / ePub

Swift 2 Design Patterns

Language: English

Pages: 224

ISBN: 1785887610

Format: PDF / Kindle (mobi) / ePub


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.

RasPi Magazine [UK], Issue 16 (2015)

Rails for .NET Developers (Facets of Ruby)

Practices of an Agile Developer: Working in the Real World (Pragmatic Bookshelf)

Flow-Based Programming: A New Approach To Application Development (2nd Edition)

Learning Ruby

RasPi Magazine, Issue 21

 

 

 

 

 

 

 

 

 

 

 

 

 

return name! } override func getDescription() -> String { return description! } override func getPrice() -> Double { return price! } override func display() { print(" \(name!), \(price!), } ---- } [ 54 ] \(description!)") Chapter 3 See how I have defined the private variables with !. This means that the values of these variables cannot be nil after initialization. This is true because we added a constructor (the init method) where all our arguments must be passed to initialize our private

code: //USAGE let horrorCategory = VODCategory(name: "Horror", description: "Horror movies category") let tvSeriesCategory = VODCategory(name: "TV Series", description: "TV Series category") let comedyCategory = VODCategory(name: "Comedy", description: "Comedy category") let voSTTvSeries = VODCategory(name: "VOSTSeries", description: "VOST TV Series sub category") let allVODComponents = VODCategory(name: "All VOD", description: "All vod components") let vodManager = VODManager(vod:

ensures that a class has only one instance. This class provides a unique point of access that returns this instance. The abstract factory pattern This pattern allows you to create an object that is grouped in families by hiding the concrete classes that are needed to create these objects. The builder pattern This pattern allows you to separate the creation of complex objects from their implementation. This permits a client to create complex objects having different representations. The

NonTerminalExpression node uses the context to store and access the state of the interpreter. Illustration We want to create a roman number converter; you know the ones that interpret that XIV means 14 in decimals. The main purpose of our example is to write a roman number and our converter will tell us the decimal value. Implementation Open the InterpreterPattern.xcodeproj file and see how we have implemented the pattern. For this pattern, all the code has been added to the main.swift class

[9] Creational Patterns // our Factory Class // Depending what we need, this class return an instance of the // appropriate object. class CardFactory{ class func createCard(cardtype: CardType) -> Card?{ switch cardtype { case .FacelessManipulator: return FacelessManipulatorCard() case .RaidLeader: return RaidLeaderCard() default: return nil } } } //Concrete Card "Raid Leader" //This is the full definition of the Raid Leader Card class RaidLeaderCard: AbstractCard { override init() {

Download sample

Download