✨ ARCANUM RUNE DIFFICULTY: Apprentice Creational

The Builder Hex

Construct complex arcane data structures step by step.

✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Builder
ARCANUM SCHOOL: Conjuration // Construct Assembly
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// CODEX INCANTATION //
use fmt;

type Golem = struct {
	head: str,
	body: str,
	arms: str,
};

type GolemBuilder = struct {
	golem: Golem,
};

fn new_builder() GolemBuilder = {
	return GolemBuilder { golem = Golem { head = "", body = "", arms = "" } };
};

fn build_head(b: *GolemBuilder, head: str) void = {
	b.golem.head = head;
};

fn build_body(b: *GolemBuilder, body: str) void = {
	b.golem.body = body;
};

fn get_golem(b: *GolemBuilder) Golem = {
	return b.golem;
};

export fn main() void = {
	let b = new_builder();
	build_head(&b, "Titanium Cranium");
	build_body(&b, "Carbon Fiber Chassis");
	let g = get_golem(&b);
	fmt::printfln("Constructed: {} with {}", g.head, g.body)!;
};

When the sigils required for instantiation grow too numerous, the Builder separates the construction of a complex object from its representation, ensuring safety in your summoning routines.

Runic Tags: #creational #builder #simple-systems-hexes