The Composite Pattern
Treating individual spells and spell combinations uniformly.
✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Composite
ARCANUM SCHOOL: Illusion // Gestalt
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// SWIFT PATTERN //
protocol SpellComponent {
func cast()
}
class SimpleSpell: SpellComponent {
func cast() { print("Casting simple spell") }
}
class MacroSpell: SpellComponent {
private var components: [SpellComponent] = []
func add(_ component: SpellComponent) { components.append(component) }
func cast() { components.forEach { $0.cast() } }
}
The Composite: The Macro Spell
With the Composite pattern, a magus can weave simple spells into a MacroSpell, executing them all with a single word of power.
Runic Tags:
#swift
#design-pattern
#structural