💠 F# SIGILS DIFFICULTY: Adept Creational

The Abstract Factory Sigil

Summoning families of related functional wards without specifying their concrete implementations.

✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Abstract Factory
ARCANUM SCHOOL: Conjuration // Sigilcraft
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// FSHARP PATTERN //
type Ward = { Power: int; Name: string }
type Shield = { Capacity: int; Element: string }

type IWardFactory =
    abstract member CreateWard: unit -> Ward
    abstract member CreateShield: unit -> Shield

let arcaneFactory =
    { new IWardFactory with
        member _.CreateWard() = { Power = 100; Name = "Arcane Barrier" }
        member _.CreateShield() = { Capacity = 500; Element = "Arcane" } }

let voidFactory =
    { new IWardFactory with
        member _.CreateWard() = { Power = 150; Name = "Void Ripple" }
        member _.CreateShield() = { Capacity = 300; Element = "Void" } }

let manifestDefenses (factory: IWardFactory) =
    let ward = factory.CreateWard()
    let shield = factory.CreateShield()
    printfn "Manifested %s and %s shield." ward.Name shield.Element

The Abstract Factory in the realm of F# is often distilled into records of functions or interfaces. Here, we bind functions into a cohesive interface representing a school of warding, ensuring that arcane defenses are perfectly attuned to their respective elemental domains.

Runic Tags: #creational #abstract-factory #fsharp #wards