✨ ARCANUM RUNE DIFFICULTY: Adept Structural

The Bridge of Spell Casting

Decouple abstraction from implementation using generic phantom types in Move.

✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Bridge
ARCANUM SCHOOL: Evocation // Channeling
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// CODEX INCANTATION //
module arcane::bridge {
    // Abstraction
    struct Spell<phantom Implementation> has store, drop {
        mana_cost: u64,
    }

    // Implementations
    struct FireMagic {}
    struct WaterMagic {}

    public fun create_fire_spell(cost: u64): Spell<FireMagic> {
        Spell { mana_cost: cost }
    }

    public fun cast<Impl>(spell: &Spell<Impl>): u64 {
        spell.mana_cost
    }
}
Runic Tags: #structural #bridge #move #phantom-types