The Prototype Pattern
Cloning existing magical entities to save arcane energy.
✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Prototype
ARCANUM SCHOOL: Illusion // Cloning
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// SWIFT PATTERN //
protocol Clonable {
func clone() -> Self
}
class MagicApple: Clonable {
var color: String
init(color: String) { self.color = color }
func clone() -> Self {
return type(of: self).init(color: self.color)
}
}
The Prototype: Mirroring the Apple
Instead of expending vast amounts of mana to conjure new apples from scratch, the Prototype pattern allows Swift casters to duplicate an existing MagicApple.
Runic Tags:
#swift
#design-pattern
#creational