Factory Method of the Shadow Forges
Define an interface for creating a cyber-magical entity, but let subclasses alter the type of entity created.
✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Factory Method
ARCANUM SCHOOL: Conjuration // Artifice
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// RUST IDIOMATIC PATTERN //
pub trait Daemon {
fn execute_payload(&self);
}
pub trait DaemonForge {
fn spawn_daemon(&self) -> Box<dyn Daemon>;
fn deploy(&self) {
let daemon = self.spawn_daemon();
daemon.execute_payload();
}
}
pub struct StealerDaemon;
impl Daemon for StealerDaemon {
fn execute_payload(&self) { println!("Siphoning corporate credits..."); }
}
pub struct StealerForge;
impl DaemonForge for StealerForge {
fn spawn_daemon(&self) -> Box<dyn Daemon> { Box::new(StealerDaemon) }
}
Deep within the Shadow Forges, the Factory Method allows masters to decree the deployment strategies of autonomous daemons while delegating the specific summoning rituals to subordinate forges.
This abstraction ensures that the central command logic remains pure and untainted by the messy specifics of varied demonic sub-protocols. To add a new breed of terror to the grid, one merely erects a new forge.
Runic Tags:
#creational
#factory-method
#conjuration
#daemons