🧱 B PRECURSOR DIFFICULTY: Adept Behavioral

The State

Mutating the behavior of an ancient artifact as its internal word alters.

✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: State
ARCANUM SCHOOL: Transmutation // Polymorph
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// B PATTERN //
/* The artifact's behavior changes depending on the pointer in its state word */
ext current_state_func;

state_dormant() {
    putchar('Z'); putchar('Z'); putchar('Z');
    current_state_func = state_awakened; /* Transition */
}

state_awakened() {
    putchar('W'); putchar('A'); putchar('K');
}

poke_artifact() {
    (current_state_func)();
}

ritual() {
    current_state_func = state_dormant;
    poke_artifact(); /* Prints ZZZ, switches to awake */
    poke_artifact(); /* Prints WAK */
}
Runic Tags: #b #design-pattern #precursor #bell-labs-magic #untyped