The Factory Method (Racket)
Delegate the specific instantiation of magical essences to subclass-like functions.
✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Factory Method
ARCANUM SCHOOL: Conjuration // Essence
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// RACKET PATTERN //
#lang racket
(define (summon-familiar type)
(case type
[(owl) (λ () "Hoot! I am an Owl familiar.")]
[(cat) (λ () "Meow! I am a Cat familiar.")]
[(dragon) (λ () "Roar! I am a Dragon familiar.")]
[else (error "Unknown familiar type")]))
(define my-owl (summon-familiar 'owl))
(define my-dragon (summon-familiar 'dragon))
(displayln (my-owl))
(displayln (my-dragon))
The Factory Method
The Factory Method defines an interface for creating an object, but leaves the choice of its type to the subclasses—or in Racket’s case, the specific branch of a higher-order function. summon-familiar acts as the arcane nexus, dynamically returning a new thunk representing the summoned creature. Metamagic made simple and elegant through #lang racket.
Runic Tags:
#racket
#creational
#factory-method
#macro-metamagic