The Builder Design Pattern in Swift
Make it this way
Difficulty: Beginner | Easy | Normal | Challenging
This article has been developed using Xcode 11.5, and Swift 5.2.4
Prerequisites:
- You will be expected to be aware of how to make a Single View Application in Swift.
Terminology:
Design Pattern: a general, reusable solution to a commonly occurring problem
The Builder Pattern in Swift
The builder pattern creates complex objects step by step, and the name brings to mind an assembly line where we are creating a complex object operation by operation.
This avoids creating initializers that grow the hierarchy into a considerable number of subclasses, or creating a giant constructor that has many parameters — and neither makes for a great code review!
The detail
The builder constructs objects in a stepwise fashion. This is great and helps avoid massive constructors!
This means
- reusability is enhanced since the same code can be used in various representations of objects
- The Single Responsibility Principle is followed, as complex construction…