The Builder Pattern
Step-by-step assembly of complex magical constructs safely.
✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Builder
ARCANUM SCHOOL: Transmutation // Constructmancy
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// SWIFT PATTERN //
class Golem {
var head: String = ""
var body: String = ""
var limbs: String = ""
}
protocol GolemBuilder {
func buildHead()
func buildBody()
func buildLimbs()
func getResult() -> Golem
}
class OrchardGolemBuilder: GolemBuilder {
private var golem = Golem()
func buildHead() { golem.head = "Applewood Head" }
func buildBody() { golem.body = "Bark Body" }
func buildLimbs() { golem.limbs = "Branch Limbs" }
func getResult() -> Golem { return golem }
}
The Builder: Constructing the Orchard Golem
The Builder pattern separates the construction of a complex magical construct from its representation. By using an OrchardGolemBuilder, a Swift sorcerer can safely initialize properties step-by-step.
Runic Tags:
#swift
#design-pattern
#creational