The Composite Gestalt
Treat individual spells and sprawling ritual arrays uniformly as a single magical tree.
β§ GANG OF FOUR LINEAGE & ARCANUM β§
GOF DESIGN PATTERN: Composite
ARCANUM SCHOOL: Illusion // Gestalt
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// SCALA PATTERN //
sealed trait SpellComponent {
def manaCost: Int
}
case class SimpleSpell(cost: Int) extends SpellComponent {
override def manaCost: Int = cost
}
case class SpellArray(components: List[SpellComponent]) extends SpellComponent {
override def manaCost: Int = components.map(_.manaCost).sum
}
// Usage:
// val array = SpellArray(List(SimpleSpell(10), SpellArray(List(SimpleSpell(5), SimpleSpell(15)))))
// println(array.manaCost) // 30
Trees of pure functional magic. The Composite pattern elegantly models recursive magical structures using Scalaβs sealed traits and case classes.
Runic Tags:
#scala
#structural
#fractal-magic