✨ ARCANUM RUNE DIFFICULTY: Apprentice Creational

The Factory Method

A polymorphic glyph that delegates the manifestation of specific entities to specialized sub-wards.

✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Factory Method
ARCANUM SCHOOL: Conjuration // Invocation
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// CODEX INCANTATION //
(* Gallina Ward: Factory Method *)
Require Import String.

Inductive EntityType :=
  | Daemon
  | Sprite.

Record Entity := mkEntity {
  name : string;
  power : nat
}.

Definition summonDaemon : Entity := mkEntity "NullDaemon" 100.
Definition summonSprite : Entity := mkEntity "ByteSprite" 10.

Definition summon (t : EntityType) : Entity :=
  match t with
  | Daemon => summonDaemon
  | Sprite => summonSprite
  end.
Runic Tags: #factory-method #gallina #wards