Description
Course info
Rating
(37)
Level
Intermediate
Updated
Dec 5, 2016
Duration
1h 18m
Description

Software design patterns are standard, proven ways to solve various problems programmers encounter. In this course, Design Patterns in Swift: Creational, you'll learn about the creational patterns using UML diagrams and practical Swift code examples. You'll begin the course with an introductory module about the history of design patterns, the values they provide, and their limitations. A brief Unified Modeling Language Primer will introduce the concepts and the diagrams used throughout this course. Next, you'll jump right into the creational patterns, which will feature the Singleton first. You'll explore thread safety using Grand Central Dispatch, generics, and readers. Then, you'll discover the Prototype pattern and concepts like the cloning of value and reference types, the difference between shallow and deep copying of objects, and under-the-hood optimizations like the copy-on-write. Finally, you'll learn the Builder pattern followed by the Factory Method design pattern. By the end of this course, you will be better prepared to implement creational design patterns in Swift.

About the author
About the author

Karoly is a veteran (mobile) developer having built several successful iOS apps and games, most of which were featured by Apple.

More from the author
Design Patterns in Swift: Behavioral
Intermediate
2h 36m
Dec 28, 2017
Design Patterns in Swift: Structural
Intermediate
1h 15m
Apr 5, 2017
Section Introduction Transcripts
Section Introduction Transcripts

Course Overview
Hi everyone, my name is Karoly Nyisztor, and I'm happy to welcome you to my course Design Patterns in Swift: Creational. I am a developer, a book author, and a software architect. Having been a professional iOS developer since 2009, I started using Swift right after its launch back in 2014. This course is an overview of the creational design patterns and the way they are implemented using Swift 3. 0, Apple's latest iteration of their popular programming language. We begin the course with an introductory module about the history of design patterns, the values they provide, and their limitations. A brief Unified Modeling Language primer will introduce the concepts and the diagrams used throughout this course. Then we jump right into the creational patterns. First comes the singleton. We are going to talk about thread safety using Grand Central Dispatch, generics, and readers-writer lock. We then talk about the prototype pattern and concepts like the cloning of value and reference types, the difference between shallow and deep copying of objects, and under the hood optimizations like the copy-on-write. Next comes the builder pattern, followed by the factory method design pattern. We finish up the course with the abstract factory design pattern. By the end of this course, you should know how to implement creational design patterns in Swift. Before beginning the course, you should be familiar with the basics of programming, but you need not have actually worked with Swift itself. I hope you will join me on this journey to learn design patterns with the Design Patterns in Swift: Creational course here at Pluralsight.

Introduction & Prerequisites
Hello, before we jump into the patterns themselves, let me introduce you to some information that is useful not only for this course, but also for the courses that are going to follow covering the other design patterns. In this preliminary module, I am going to talk about the history of design patterns, the value they provide, and their limitations. A brief UML primer will follow where I introduce some of the UML concepts and diagrams used throughout this course. Finally, I will provide an overview of the design patterns organized by categories. In the second module, we talk about the creational design patterns. First comes the singleton. Then we talk about the prototype design pattern. Next comes the builder, followed by the factory method design pattern. We finish up the course with the abstract factory design pattern. For each design pattern, we discuss the following: when to use the given pattern, how can it be represented using UML, and finally, how can it be implemented using Swift 3. 0.

Singleton
Hi, and welcome to another module in the Swift Design Patterns: Creational course. In this module, we are going to take a look at the singleton pattern. After discussing what the singleton is and when you should use it, I am going to show you how to implement it it Swfit 3. 0. We are going to implement a singleton class named SessionState. The SessionState class will act as a center repository for various application settings. Since application settings can be stored and retrieved in parallel by several threads, the SessionState class must be thread-safe to prevent data corruption. I will show you how to ensure the thread safety of our singleton using Grand Central Dispatch. The singleton pattern ensures the uniqueness of an object. You implemented the pattern correctly if only one instance of the given type can be created and that instance cannot be cloned. The singleton instance must be thread-safe since many different components might access it concurrently. You must implement protection against concurrent use for the initialization phase of the singleton and any access to its public properties or methods. To recap, the singleton pattern ensures only one instance of a given type exists, and that instance cannot be copied or cloned. The singleton must be thread-safe since the shared instance can be concurrently accessed by several threads. Okay, so let's implement our SessionState singleton class in Swift 3. 0. First, I am going to show you how to prevent the creation of multiple instances and the cloning of the SessionState object. Next, we will discuss how to protect the singleton against concurrent use.

Builder
Hi there, and welcome to this module on the builder pattern. First, I talk about what the builder pattern is and the motivation behind using it. Then we are going to look at how to implement the builder pattern. The final goal is to create a ThemeBuilder class, which lets us easily configure and instantiate themes which define the colors and fonts used in an application. The builder pattern helps when we need to create complex objects which require many configuration values. The builder pattern is a good choice when the objects to be created can usually use some predefined defaults, and you rarely need to modify these values. The point is that callers can customize the default configuration values, but usually most of these defaults remain unchanged. This pattern encapsulates the default configuration values and the required set-up logic required to create an object into a builder class. The builder pattern separates the configuration of an object from its creation. It simplifies the creation of instances which need many default values, and those values usually don't change frequently when creating new objects. Okay, so let's implement our ThemeBuilder demo in Swift 3. 0.

Factory Method
Hello, in this module, we are going to talk about the factory method pattern. First, I am going to talk about the motivation behind using the factory method pattern. Then we are going to implement the ColorThemePicker component, which allows choosing a color palette using the factory method design pattern. The factory method pattern allows callers to create instances of objects by only knowing the protocol or the top level base class and not the exact implementation classes. This way callers must not know any details about the implementation classes. The factory method incorporates the logic required to decide which implementation class to instantiate based on the criteria supplied by the caller. Callers must not know all the implementation classes, just the protocol or the base class. In the demo that follows, we are going to implement the way to create color palettes using the factory method design pattern.

Abstract Factory
Hello. In this module, we are going to talk about the abstract factory. This pattern is similar to the factory method pattern, except that it returns a set of related objects instead of just one. First, I am going to talk about the motivation behind using the abstract factory pattern. Then we are going to implement the ComputerShop demo app to demonstrate the real-life application of this pattern. The motivation behind using the abstract factory design pattern is to create objects which belong to a group, but inherit from several different base classes or implement different protocols. The actual classes which are used to create the objects remained hidden, which lets us modify the factory without having to refactor the caller's code. The abstract factory design pattern is similar to the factory method pattern, but the caller does not know which classes were involved in the creation process. The approach makes it possible to change the factory classes without modifying the callers. The abstract factory design pattern should be applied when you need to create a set of related objects. To create single objects, choose the factory method pattern instead. I am going to showcase the abstract factory pattern by implementing a demo which lets us create different computer configurations.