🥞 FORTH STACK DIFFICULTY: Adept Creational

Factory Method (Forth)

Defer creation to the defining words of the Necromancer.

✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Factory Method
ARCANUM SCHOOL: Conjuration // Runesmithing
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// FORTH PATTERN //
\ Runesmithing: The Factory Method
\ We use CREATE ... DOES> to spawn customized words (entities).

: DAEMON-SPAWNER ( power "name" -- )
  CREATE ,             \ Store power level in dictionary
  DOES> @              \ When called, fetch power level
  ." Daemon unleashed with power: " . CR ;

\ Factory instantiation:
10 DAEMON-SPAWNER LESSER-DAEMON
50 DAEMON-SPAWNER GREATER-DAEMON

\ Usage:
\ LESSER-DAEMON
\ GREATER-DAEMON

In Forth, the Factory Method is seamlessly handled by CREATE ... DOES>. The parent word acts as the factory, stamping out child words imbued with specific runtime behaviors and sealed data.

Runic Tags: #creational #factory-method #forth #runesmithing