⚡ ZIG ALCHEMY DIFFICULTY: Adept Creational

The Prototype: Biomimicry

Clone existing magical entities without coupling to their specific arcane classes.

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

pub const Cloneable = struct {
    vtable: *const VTable,

    pub const VTable = struct {
        clone: *const fn (self: *const Cloneable, alloc: std.mem.Allocator) std.mem.Allocator.Error!*Cloneable,
    };

    pub fn clone(self: *const Cloneable, alloc: std.mem.Allocator) !*Cloneable {
        return self.vtable.clone(self, alloc);
    }
};

In the bleeding edge of aetheric cloning, the Prototype pattern avoids the heavy toll of reconstructing complex objects from scratch. By implementing a cloneable interface, one simply siphons a copy of the existing entity’s memory footprint into a new explicit allocation. Biomimicry at the speed of thought.

Runic Tags: #prototype #creational #zig #biomimicry