Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Swift 2 Design Patterns

You're reading from   Swift 2 Design Patterns Build robust and scalable iOS and Mac OS X game applications

Arrow left icon
Product type Paperback
Published in Oct 2015
Publisher
ISBN-13 9781785887611
Length 224 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Julien Lange Julien Lange
Author Profile Icon Julien Lange
Julien Lange
Arrow right icon
View More author details
Toc

Chapter 1. Creational Patterns

The creational patterns are designed to deal with the object creation mechanism in software designing. A system using these patterns becomes independent of how objects are created, which means it is independent of how concrete classes are instantiated.

These patterns encapsulate the use of concrete classes and favor the use of interfaces in the relationship between objects, allowing to have better abstraction of the global system conception.

Thus, if we analyze the singleton pattern, a pattern designed to instantiate only one instance of a class, we find that the mechanism that controls the unique access to this instance is fully encapsulated in the class, which means that this is completely transparent to the client consuming the instance of the class.

In this chapter, we will introduce you to the five creational patterns and discuss how we can use them with Swift:

  • The prototype pattern
  • The factory method pattern
  • The singleton pattern
  • The abstract factory pattern
  • The builder pattern

The objectives of these patterns are described in the following table:

Pattern

Objective

The prototype pattern

This pattern allows you to create new objects by duplicating existing objects called prototypes. This pattern has the cloning capability.

The factory method pattern

This pattern introduces you to an abstract method that allows you to create an object by telling its subclasses about the effective creation of the object.

The singleton pattern

This pattern 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.

You have been reading a chapter from
Swift 2 Design Patterns
Published in: Oct 2015
Publisher:
ISBN-13: 9781785887611
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image