The Command Hex
Encapsulating arcane intents into executable crystals.
✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Command
ARCANUM SCHOOL: Enchantment // Binding
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// KOTLIN PATTERN //
interface SpellCommand {
fun execute()
fun undo()
}
class TeleportCommand(private val target: String) : SpellCommand {
override fun execute() = println("Teleporting to $target")
override fun undo() = println("Recalling from $target")
}
class Wand {
private val history = mutableListOf<SpellCommand>()
fun cast(command: SpellCommand) {
command.execute()
history.add(command)
}
fun rewind() {
if (history.isNotEmpty()) history.removeLast().undo()
}
}
The Command Hex
Intent alone is not enough; it must be crystallized. The Command pattern wraps an invocation into a distinct object, allowing it to be queued, delayed, or inverted. This is essential for temporal magic, allowing a wand to keep a history of cast spells and unweave them via the undo invocation.
Runic Tags:
#kotlin
#behavioral
#command