💠 F# SIGILS DIFFICULTY: Apprentice Structural

The Decorator Ward

Dynamically weaving additional protective layers onto an existing spell.

✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Decorator
ARCANUM SCHOOL: Abjuration // Layering
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// FSHARP PATTERN //
type ISpell =
    abstract member Cast: unit -> string

type BaseSpell() =
    interface ISpell with
        member _.Cast() = "A fundamental pulse of magic."

type SpellDecorator(spell: ISpell) =
    interface ISpell with
        member _.Cast() = spell.Cast()

type EmpoweredSpell(spell: ISpell) =
    inherit SpellDecorator(spell)
    interface ISpell with
        member _.Cast() = (spell.Cast()) + " Now crackling with raw power!"

type EchoingSpell(spell: ISpell) =
    inherit SpellDecorator(spell)
    interface ISpell with
        member _.Cast() = (spell.Cast()) + " It echoes across the astral plane."

let coreSpell = BaseSpell()
let empowered = EmpoweredSpell(coreSpell)
let echoedAndEmpowered = EchoingSpell(empowered)

printfn "%s" ((echoedAndEmpowered :> ISpell).Cast())

Rather than subclassing EmpoweredEchoingSpell, the Decorator pattern allows magi to layer sigils sequentially, wrapping a core invocation in successive augmenting runes.

Runic Tags: #structural #decorator #fsharp #wards