✨ ARCANUM RUNE DIFFICULTY: Apprentice Creational

The Builder: Assembling the Golem

Separate the construction of a complex object from its representation.

✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Builder
ARCANUM SCHOOL: Transmutation // Synthesis
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// CODEX INCANTATION //
public class GNOMEArtifice.MechBuilder : Object {
    private string chassis = "Basic Frame";
    private string weapon = "None";
    private string core = "Standard Battery";

    public MechBuilder set_chassis(string chassis) {
        this.chassis = chassis;
        return this;
    }

    public MechBuilder set_weapon(string weapon) {
        this.weapon = weapon;
        return this;
    }

    public MechBuilder set_core(string core) {
        this.core = core;
        return this;
    }

    public Mech build() {
        return new Mech(this.chassis, this.weapon, this.core);
    }
}

public class GNOMEArtifice.Mech : Object {
    public string chassis { get; private set; }
    public string weapon { get; private set; }
    public string core { get; private set; }

    public Mech(string chassis, string weapon, string core) {
        this.chassis = chassis;
        this.weapon = weapon;
        this.core = core;
    }

    public void activate() {
        print(@"Mech activated with $(this.chassis), $(this.weapon), and a $(this.core) core.\n");
    }
}

Constructing complex automatons in the GNOME Artifice requires precision. A solitary incantation with a dozen parameters invites chaos and runtime segmentation faults. The Builder pattern provides a methodical ritual for assembling your Golem, step by step. You dictate its chassis, equip its weaponry, and ignite its core sequentially, culminating in a build() invocation that awakens the machine in its final, pristine form.

Runic Tags: #Vala #GObject #Creational #Builder