🎸 GROOVY HEX DIFFICULTY: Apprentice Creational

The Factory Method Hex

Delegating the instantiation of magical entities to subclasses.

✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Factory Method
ARCANUM SCHOOL: Conjuration // Summoning
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// GROOVY PATTERN //
abstract class Summoner {
    abstract Familiar summonFamiliar()

    void manifest() {
        def familiar = summonFamiliar()
        println "Manifested: ${familiar.getType()}"
    }
}

interface Familiar { String getType() }

class CyberSummoner extends Summoner {
    Familiar summonFamiliar() { 
        return { "Mecha-Raven" } as Familiar 
    }
}

class VoidSummoner extends Summoner {
    Familiar summonFamiliar() { 
        return { "Shadow-Hound" } as Familiar 
    }
}

new CyberSummoner().manifest()
new VoidSummoner().manifest()

The Factory Method Hex

The Factory Method hex delegates the specifics of entity summoning to specialized sub-summoners. By combining this pattern with Groovy’s dynamic interface coercion from closures, a mage can define exact instantiation rules with minimal ritual overhead.

Runic Tags: #groovy #creational #factory-method #closures