The Decorator Pattern
Dynamically attaching new magical properties to objects.
β§ GANG OF FOUR LINEAGE & ARCANUM β§
GOF DESIGN PATTERN: Decorator
ARCANUM SCHOOL: Transmutation // Enhancement
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// SWIFT PATTERN //
protocol Wand {
func power() -> Int
}
class BasicWand: Wand {
func power() -> Int { return 10 }
}
class GemEnchantment: Wand {
private let baseWand: Wand
init(baseWand: Wand) { self.baseWand = baseWand }
func power() -> Int { return baseWand.power() + 5 }
}
The Decorator: Enhancing the Wand
The Decorator allows us to augment a BasicWand with a GemEnchantment without altering the original wandβs internal essence.
Runic Tags:
#swift
#design-pattern
#structural