🔴 SCALA ALCHEMY DIFFICULTY: Apprentice Behavioral

The Observer Scrying

Allow a legion of scrying orbs to automatically react when a distant leyline surges.

✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Observer
ARCANUM SCHOOL: Divination // Scrying
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// SCALA PATTERN //
trait ScryingOrb {
  def onLeylineSurge(power: Int): Unit
}

class Leyline {
  private var orbs = List.empty[ScryingOrb]

  def bind(orb: ScryingOrb): Unit = orbs = orb :: orbs

  def surge(power: Int): Unit = {
    println(s"Leyline surges with power $power!")
    orbs.foreach(_.onLeylineSurge(power))
  }
}

class DarkOrb extends ScryingOrb {
  def onLeylineSurge(power: Int): Unit = println(s"DarkOrb gleans $power souls.")
}

The standard publish-subscribe model of the arcane world. The Leyline remains ignorant of who watches it, maintaining loose coupling.

Runic Tags: #scala #behavioral #divination #pub-sub