✨ ARCANUM RUNE DIFFICULTY: Apprentice Creational

The Factory Method Incantation in Carbon

Delegate the exact class of a summoned entity to the subclasses that implement the summoning circle.

✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Factory Method
ARCANUM SCHOOL: Conjuration // Summoning
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// CODEX INCANTATION //
package FactoryMethod api;

interface ArcaneEntity {
  fn Manifest[me: Self]() -> String;
}

class NeonPhantom {
  impl as ArcaneEntity {
    fn Manifest[me: Self]() -> String { return "A phantom of neon emerges."; }
  }
}

class ChromiumSprite {
  impl as ArcaneEntity {
    fn Manifest[me: Self]() -> String { return "A sprite of chromium darts by."; }
  }
}

interface Summoner {
  fn Summon[me: Self]() -> auto;
}

class PhantomSummoner {
  impl as Summoner {
    fn Summon[me: Self]() -> auto { return NeonPhantom(); }
  }
}

class SpriteSummoner {
  impl as Summoner {
    fn Summon[me: Self]() -> auto { return ChromiumSprite(); }
  }
}

The Factory Method: The Summoner’s Discretion

In the Carbon ecosystem, where interfaces and implementations cleanly detach, the Factory Method thrives. It allows the core summoning engine to orchestrate the ritual without knowing the exact entity being summoned.

The Successor Pact dictates that we must avoid the tight coupling that plagued our ancestors. By utilizing the Factory Method, a Summoner interface guarantees that an ArcaneEntity will be produced, but leaves the precise spectral signature to the concrete PhantomSummoner or SpriteSummoner.

Runic Tags: #creational #carbon #inheritance