The Factory Method Hex
Deferring the manifestation of entities to the subclasses.
β§ GANG OF FOUR LINEAGE & ARCANUM β§
GOF DESIGN PATTERN: Factory Method
ARCANUM SCHOOL: Conjuration // Summoning
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// KOTLIN PATTERN //
sealed class Familiar
class Raven : Familiar()
class Cat : Familiar()
abstract class Summoner {
abstract fun summon(): Familiar
fun bind() {
val familiar = summon()
println("Binding ${familiar::class.simpleName} to the soul...")
}
}
class ShadowSummoner : Summoner() {
override fun summon() = Raven()
}
The Factory Method Hex
When a Summoner calls into the aether, they know not exactly which familiar will heed the call. By utilizing the Factory Method, we defer the exact instantiation logic to specialized covens. Combined with Kotlinβs sealed classes, we ensure our summoned entities are strictly bounded within the known magical taxonomies.
Runic Tags:
#kotlin
#creational
#factory-method