🔧 TCL GLYPH DIFFICULTY: Apprentice Creational

The Factory Method

Defines an interface for creating a single magical entity, letting subclasses alter the type of entity created.

✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Factory Method
ARCANUM SCHOOL: Conjuration // Manifestation
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// TCL PATTERN //
oo::class create Grimoire {
    method createScroll {} { error "Not implemented" }
    method readScroll {} {
        set scroll [my createScroll]
        $scroll invoke
        $scroll destroy
    }
}

oo::class create FireScroll { method invoke {} { puts "A burst of cyber-flame engulfs the terminal!" } }
oo::class create IceScroll { method invoke {} { puts "Sub-zero ICE locks the process threads." } }

oo::class create PyromancerGrimoire {
    superclass Grimoire
    method createScroll {} { return [FireScroll new] }
}

oo::class create CryomancerGrimoire {
    superclass Grimoire
    method createScroll {} { return [IceScroll new] }
}

set book [PyromancerGrimoire new]
$book readScroll

The Factory Method

The Grimoire holds the template, but the specific path of the magus dictates the spell cast. By deferring instantiation to subclasses, TclOO allows dynamic generation of scripts tailored to the immediate systemic threat.

Runic Tags: #creational #factory #tcloo #manifestation