⚙️ JSONNET RUNE DIFFICULTY: Apprentice Structural

The Flyweight of Jsonnet

Sharing common state to reduce memory footprint.

✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Flyweight
ARCANUM SCHOOL: Conjuration // Essence Sharing
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// JSONNET PATTERN //
local SharedLabels = {
  environment: "production",
  managed_by: "jsonnet-sorcery"
};

local Service(name) = {
  name: name,
  labels: SharedLabels
};

{
  srv1: Service("auth"),
  srv2: Service("billing")
}

By capturing common data in a shared local variable, Jsonnet implements the Flyweight pattern, reusing the exact same data reference across multiple objects to keep the arcane footprint minimal.

Runic Tags: #structural #flyweight #jsonnet