✨ ARCANUM RUNE DIFFICULTY: Archmage Structural

The Flyweight

Using sharing to support large numbers of fine-grained magic particles efficiently.

✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Flyweight
ARCANUM SCHOOL: Conjuration // Swarm Control
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// CODEX INCANTATION //
class RuneTexture {
  constructor(public glyphCode: string) {} // Intrinsic state
}

class RuneFactory {
  private cache: Map<string, RuneTexture> = new Map();
  getTexture(code: string): RuneTexture {
    if (!this.cache.has(code)) {
      this.cache.set(code, new RuneTexture(code));
    }
    return this.cache.get(code)!;
  }
}

class FloatingRune {
  constructor(private texture: RuneTexture, private x: number, private y: number) {} // Extrinsic state
  draw() { console.log(`Drawing ${this.texture.glyphCode} at ${this.x},${this.y}`); }
}

The Flyweight pattern minimizes memory usage by sharing as much data as possible with similar objects. When summoning a swarm of ten thousand protective runes, storing the intrinsic visual data in a single shared texture prevents a catastrophic memory overload within the arcane processor.

Runic Tags: #structural #typescript #flyweight