⚙️ MOTOKO RUNE DIFFICULTY: Adept Creational

The Prototype Hex

Cloning an existing actor's memory state to manifest a spectral duplicate.

✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Prototype
ARCANUM SCHOOL: Illusion // Actor Model Hexes
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// MOTOKO PATTERN //
module Prototype {
  public type SpectralClone = {
    clone : () -> SpectralClone;
    haunt : () -> async Text;
    setTarget : (Text) -> ();
  };

  public class Phantom(initialTarget : Text) {
    var currentTarget : Text = initialTarget;

    public func haunt() : async Text {
      "Haunting " # currentTarget;
    };

    public func setTarget(t : Text) : () {
      currentTarget := t;
    };

    public func clone() : SpectralClone {
      Phantom(currentTarget); // Duplicate the current spectral state
    };
  };

  public actor Phylactery {
    var templatePhantom = Phantom("The Unworthy");

    public func unleashSwarm() : async [SpectralClone] {
      let clone1 = templatePhantom.clone();
      let clone2 = templatePhantom.clone();
      
      clone2.setTarget("The Innocent");
      
      [clone1, clone2];
    };
  };
}

The Prototype Hex enables the duplication of complex, stateful apparitions without running through their original, potentially expensive summoning rites. By relying on a clone method, new instances are torn directly from the astral fabric of an existing phantom.

Runic Tags: #motoko #creational #prototype #actor-model