🔴 SCALA ALCHEMY DIFFICULTY: Adept Behavioral

The Mediator Nexus

Prevent elemental factions from destroying each other by routing their communications through a central hub.

✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Mediator
ARCANUM SCHOOL: Enchantment // Binding
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// SCALA PATTERN //
trait Council {
  def broadcast(message: String, sender: Archmage): Unit
}

class Archmage(val name: String, council: Council) {
  def speak(msg: String): Unit = council.broadcast(msg, this)
  def hear(msg: String): Unit = println(s"$name hears: $msg")
}

class HighCouncil extends Council {
  private var mages = List.empty[Archmage]

  def register(mage: Archmage): Unit = mages = mages :+ mage

  def broadcast(message: String, sender: Archmage): Unit = {
    mages.filterNot(_ == sender).foreach(_.hear(message))
  }
}

The Mediator centralizes complex communications. Instead of a chaotic web of Mages shouting at one another, the HighCouncil guarantees orderly resolution.

Runic Tags: #scala #behavioral #binding #decoupling