The Mediator
Define an object that encapsulates how a set of objects interact.
✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Mediator
ARCANUM SCHOOL: Enchantment // Nexus Binding
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// CODEX INCANTATION //
structural type Entity = Golem | Wizard
structural type Event = Attack | Defend
ability Nexus where
broadcast : Entity -> Event -> ()
golemBehavior : '{Nexus} ()
golemBehavior _ =
Nexus.broadcast Golem Attack
wizardBehavior : '{Nexus} ()
wizardBehavior _ =
Nexus.broadcast Wizard Defend
nexusHandler : '{Nexus} a -> a
nexusHandler comp =
h : Request Nexus a -> a
h = cases
{Nexus.broadcast ent evt -> resume} ->
-- The mediator logic determining interaction
match (ent, evt) with
(Golem, Attack) -> handle resume () with h
(Wizard, Defend) -> handle resume () with h
_ -> handle resume () with h
{a} -> a
handle !comp with h
When multiple arcane constructs must communicate, direct entanglements lead to chaotic, brittle weaves. The Mediator pattern centralizes this communication. In Unison, the Mediator is a powerful Ability handler (nexusHandler). Constructs broadcast their intents as effects, and the handler interprets and routes these events according to the global laws of the interaction nexus.
Runic Tags:
#behavioral
#mediator
#unison
#abilities
#communication