⚡ ZIG ALCHEMY DIFFICULTY: Adept Behavioral

The Observer: scrying Orb

Define a one-to-many dependency so that when one object changes state, all its dependents are notified.

✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Observer
ARCANUM SCHOOL: Divination // Scrying
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// BLAZING-FAST ZIG ALCHEMY //
const std = @import("std");

pub const Watcher = struct {
    vtable: *const VTable,
    pub const VTable = struct {
        update: *const fn (self: *Watcher, energy: u32) void,
    };
    pub fn update(self: *Watcher, energy: u32) void {
        self.vtable.update(self, energy);
    }
};

pub const Core = struct {
    watchers: std.ArrayList(*Watcher),
    energy: u32,

    pub fn pulse(self: *Core) void {
        for (self.watchers.items) |w| {
            w.update(self.energy);
        }
    }
};

Scrying orbs do not constantly poll the cosmic aether—they sleep until disturbed. The Observer pattern allows a central Core to maintain a list of interested Watchers. When the Core’s state shifts, a cascading pulse immediately triggers all subscribed orbs in perfectly synchronized harmony.

Runic Tags: #observer #behavioral #zig #scrying