🕊️ SWIFT ENCHANTMENTS DIFFICULTY: Adept Structural

The Bridge Pattern

Decoupling a magical abstraction from its elemental implementation.

✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Bridge
ARCANUM SCHOOL: Transmutation // Elementalism
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// SWIFT PATTERN //
protocol Element {
    func manifest() -> String
}
class FireElement: Element {
    func manifest() -> String { return "Fire" }
}
class Spell {
    var element: Element
    init(element: Element) { self.element = element }
    func cast() -> String { return "Casting \(element.manifest()) spell" }
}

The Bridge: Elemental Decoupling

The Bridge pattern allows the essence of a Spell to vary independently from its underlying Element.

Runic Tags: #swift #design-pattern #structural