The Decorator Hex
Dynamically weaving additional wards onto a base spell.
✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Decorator
ARCANUM SCHOOL: Transmutation // Enhancement
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// KOTLIN PATTERN //
interface Spell {
val manaCost: Int
fun cast(): String
}
class BasicSpell : Spell {
override val manaCost = 10
override fun cast() = "Casting spell"
}
class EmpoweredSpell(private val spell: Spell) : Spell by spell {
override val manaCost: Int
get() = spell.manaCost + 15
override fun cast() = spell.cast() + " with immense power"
}
The Decorator Hex
When a spell requires augmentation on the fly, subclassing creates brittle grimoires. The Decorator Hex wraps an existing spell dynamically. In Kotlin, the by keyword invokes native delegation magic, allowing us to compose decorators effortlessly and extend functionality without inheriting rigid class structures.
Runic Tags:
#kotlin
#structural
#decorator