The Abstract Factory of the Progenitor
Forge cohesive families of arcane constructs using Standard ML's powerful functors.
✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Abstract Factory
ARCANUM SCHOOL: Conjuration // Modular Weaving
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// CODEX INCANTATION //
signature SPELL = sig
val cast : unit -> string
end
signature WAND = sig
val wave : unit -> string
end
signature ARCANE_FACTORY = sig
structure Spell : SPELL
structure Wand : WAND
end
structure FireFactory : ARCANE_FACTORY = struct
structure Spell = struct
fun cast () = "Casting Fireball!"
end
structure Wand = struct
fun wave () = "Waving the Ruby Wand."
end
end
structure IceFactory : ARCANE_FACTORY = struct
structure Spell = struct
fun cast () = "Casting Frost Nova!"
end
structure Wand = struct
fun wave () = "Waving the Sapphire Wand."
end
end
functor Wizard(F : ARCANE_FACTORY) = struct
fun performMagic () =
F.Wand.wave () ^ " " ^ F.Spell.cast ()
end
structure FireWizard = Wizard(FireFactory)
val invocation = FireWizard.performMagic ()
The Abstract Factory pattern in Standard ML (The ML Progenitor) is elegantly handled by the module system. We define signatures for our abstract products and the factory itself. Concrete implementations are structures, and clients that depend on the factory are written as functors, taking the factory structure as a parameter to ensure that arcane components are strictly from the same cohesive family.
Runic Tags:
#functors
#signatures
#family