Command of the Execution Scroll
Encapsulate a request as an object, thereby letting you parameterize clients with different requests.
✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Command
ARCANUM SCHOOL: Evocation // Delayed-casting
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// RUST IDIOMATIC PATTERN //
pub trait Command {
fn execute(&self);
}
pub struct OrbitalStrike {
target_coords: String,
}
impl Command for OrbitalStrike {
fn execute(&self) { println!("Calling strike on {}", self.target_coords); }
}
pub struct ExecutionQueue {
commands: Vec<Box<dyn Command>>,
}
impl ExecutionQueue {
pub fn new() -> Self { Self { commands: Vec::new() } }
pub fn add(&mut self, cmd: Box<dyn Command>) { self.commands.push(cmd); }
pub fn run_all(&self) {
for cmd in &self.commands { cmd.execute(); }
}
}
The Command pattern transmutes a fleeting intent into a permanent Execution Scroll. In the chaotic heat of a cyber-raid, executing an action immediately is often suicidal.
By encapsulating the operation as a concrete command object, you can store it, queue it, pass it across network boundaries, or even reverse it. When the precise astronomical conditions are met, the queue unloads its payload with devastating synchronicity.
Runic Tags:
#behavioral
#command
#evocation
#queueing