🕊️ SWIFT ENCHANTMENTS DIFFICULTY: Adept Behavioral

The State Pattern

Altering a magical entity's behavior when its internal state changes.

✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: State
ARCANUM SCHOOL: Transmutation // Polymorph
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// SWIFT PATTERN //
protocol ElementalState {
    func attack()
}
class WaterState: ElementalState {
    func attack() { print("Casting Water Whip") }
}
class IceState: ElementalState {
    func attack() { print("Casting Ice Shards") }
}
class Elemental {
    var state: ElementalState = WaterState()
    func attack() { state.attack() }
}

The State: The Shifting Elemental

The State pattern allows an Elemental to change its attack style dynamically as it shifts from WaterState to IceState.

Runic Tags: #swift #design-pattern #behavioral