🕊️ SWIFT ENCHANTMENTS DIFFICULTY: Apprentice Behavioral

The Command Pattern

Encapsulating a spell request as an object.

✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Command
ARCANUM SCHOOL: Evocation // Invocation
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// SWIFT PATTERN //
protocol Command {
    func execute()
}
class HealCommand: Command {
    func execute() { print("Casting Heal") }
}
class Invoker {
    private var commands: [Command] = []
    func storeAndExecute(command: Command) {
        commands.append(command)
        command.execute()
    }
}

The Command: The Stored Invocation

By encapsulating a spell as a Command, an Invoker can queue, store, or delay its execution.

Runic Tags: #swift #design-pattern #behavioral