The Abstract Factory Hex
Forge families of related artifacts in the deep systems layer.
✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Abstract Factory
ARCANUM SCHOOL: Conjuration // Systems Conjuration
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// CODEX INCANTATION //
use fmt;
type Widget = struct {
render: *fn() void,
};
fn render_neon() void = {
fmt::println("Neon Widget Glowing")!;
};
fn render_void() void = {
fmt::println("Void Widget Absorbing Light")!;
};
type Factory = struct {
create_widget: *fn() Widget,
};
fn neon_factory() Widget = {
return Widget { render = &render_neon };
};
fn void_factory() Widget = {
return Widget { render = &render_void };
};
export fn main() void = {
let f = Factory { create_widget = &neon_factory };
let w = f.create_widget();
w.render();
};
The Abstract Factory pattern allows a system magus to switch out the entire thematic output of a summoning matrix without rewriting the core control flow. In the Hare systems language, this is often done with structs containing function pointers, acting as virtual tables for your hexes.
Runic Tags:
#creational
#abstract-factory
#simple-systems-hexes