πŸ•ŠοΈ SWIFT ENCHANTMENTS DIFFICULTY: Adept Structural

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