🟣 KOTLIN HEXES DIFFICULTY: Adept Creational

The Abstract Factory Hex

A pragmatic hex for conjuring families of related runes safely.

✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Abstract Factory
ARCANUM SCHOOL: Conjuration // Rune-Weaving
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// KOTLIN PATTERN //
interface Rune {
    fun glow(): String
}

class FireRune : Rune {
    override fun glow() = "Burning red"
}

class FrostRune : Rune {
    override fun glow() = "Chilling blue"
}

interface RuneFactory {
    fun createRune(): Rune
}

class FireRuneFactory : RuneFactory {
    override fun createRune() = FireRune()
}

class FrostRuneFactory : RuneFactory {
    override fun createRune() = FrostRune()
}

The Abstract Factory Hex

In the depths of the JVM construct, where null-safety forms our protective wards, the Abstract Factory pattern allows us to summon related arcane items without knowing their true physical manifestations. By binding to abstract interfaces, our spellcrafters can weave modular invocations that swap elemental domains with a mere keystroke.

Runic Tags: #kotlin #creational #factory