The Prototype Clone
Duplicate complex magical states without re-casting the entire initialization spell.
✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Prototype
ARCANUM SCHOOL: Illusion // Duplication
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// SCALA PATTERN //
case class SpellMatrix(runes: Vector[String], potency: Double) {
// Scala case classes inherently provide a highly efficient `copy` method,
// effectively acting as the Prototype pattern organically.
def cloneMatrix(newPotency: Double = this.potency): SpellMatrix = {
this.copy(potency = newPotency)
}
}
// Usage:
// val fireball = SpellMatrix(Vector("Ignis", "Projicio"), 50.0)
// val greaterFireball = fireball.cloneMatrix(100.0)
In Scala, pure functional magic gives us case classes. The copy method is the ultimate Prototype implementation, offering type-safe alchemy to spin up new constructs from existing templates.
Runic Tags:
#scala
#creational
#illusion
#cloning