⚙️ JSONNET RUNE DIFFICULTY: Apprentice Creational

The Factory Method of Jsonnet

Delegating object creation to specific template functions.

✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Factory Method
ARCANUM SCHOOL: Conjuration // Manifestation
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// JSONNET PATTERN //
local Dialog = {
  render():: self.createButton() + { type: "Dialog" },
  createButton():: error "Abstract method: createButton must be overridden"
};

local WindowsDialog = Dialog {
  createButton():: { buttonType: "WindowsButton" }
};

local WebDialog = Dialog {
  createButton():: { buttonType: "HTMLButton" }
};

{
  winDialog: WindowsDialog.render(),
  webDialog: WebDialog.render()
}

The Factory Method provides a portal through which abstract configurations can defer their exact manifestation to derived configurations, using Jsonnet’s powerful object inheritance.

Runic Tags: #creational #factory-method #jsonnet