🎸 GROOVY HEX DIFFICULTY: Adept Behavioral

The State Hex

Allowing an entity to alter its behavior when its internal state changes.

✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: State
ARCANUM SCHOOL: Enchantment // Polymorphism
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// GROOVY PATTERN //
interface BotState { void act(Bot context) }

class PatrolState implements BotState {
    void act(Bot context) {
        println "Bot is patrolling..."
        context.state = new CombatState() // State transition
    }
}

class CombatState implements BotState {
    void act(Bot context) {
        println "Bot engages target!"
        context.state = new PatrolState()
    }
}

class Bot {
    BotState state = new PatrolState()
    void update() { state.act(this) }
}

def sentry = new Bot()
sentry.update()
sentry.update()

The State Hex

The State hex transforms branching if/else conditional logic into elegant polymorphic objects. Each state governs its own behavior and possesses the authority to shift the parent entity into a new configuration. In the cyber-realm, drones switch from patrol to combat protocols seamlessly without cluttering their core processors with tangled conditional logic.

Runic Tags: #groovy #behavioral #state