The Command Geas
Encapsulating a spell request as an object, allowing logging, queuing, and undoing of arcane decrees.
✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Command
ARCANUM SCHOOL: Enchantment // Geas
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// FSHARP PATTERN //
type ICommand =
abstract member Execute: unit -> unit
abstract member Undo: unit -> unit
type Golem() =
member _.MoveForward() = printfn "Golem steps forward heavily."
member _.MoveBackward() = printfn "Golem retreats one step."
type MoveCommand(golem: Golem) =
interface ICommand with
member _.Execute() = golem.MoveForward()
member _.Undo() = golem.MoveBackward()
type ArchmageInvoker() =
let mutable history: ICommand list = []
member _.Invoke(cmd: ICommand) =
cmd.Execute()
history <- cmd :: history
member _.UndoLast() =
match history with
| head :: tail ->
head.Undo()
history <- tail
| [] -> printfn "No spells to undo."
let stoneGolem = Golem()
let march = MoveCommand(stoneGolem)
let commander = ArchmageInvoker()
commander.Invoke(march)
commander.UndoLast()
The Command Geas transforms an imperative directive into an object or closure. By keeping a ledger of these bindings, an Archmage can rewind time, compelling constructs to reverse their actions.
Runic Tags:
#behavioral
#command
#fsharp
#geas