⚡ ZIG ALCHEMY DIFFICULTY: Adept Behavioral

The Visitor: Astral Projection

Represent an operation to be performed on the elements of an object structure without changing the classes.

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

pub const SpiritVisitor = struct {
    vtable: *const VTable,
    pub const VTable = struct {
        visitDemon: *const fn (self: *SpiritVisitor, demon: *anyopaque) void,
        visitFae: *const fn (self: *SpiritVisitor, fae: *anyopaque) void,
    };
};

pub const Entity = struct {
    vtable: *const VTable,
    pub const VTable = struct {
        accept: *const fn (self: *Entity, visitor: *SpiritVisitor) void,
    };
};

Scanning heterogenous collections of multidimensional entities is perilous. The Astral Projection injects a Visitor directly into the objects’ native dimensions via double-dispatch. New analyses can be concocted at runtime without ever altering the fragile code of the target entities.

Runic Tags: #visitor #behavioral #zig #scanning