🔧 TCL GLYPH DIFFICULTY: Adept Behavioral

The Chain of Responsibility

Passes an arcane event along a chain of handlers until one resolves it.

✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Chain of Responsibility
ARCANUM SCHOOL: Abjuration // Filtering
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// TCL PATTERN //
oo::class create Ward {
    variable nextWard
    constructor {} { set nextWard "" }
    method setNext {w} { set nextWard $w }
    method handle {threat} {
        if {$nextWard ne ""} {
            $nextWard handle $threat
        } else {
            puts "Threat '$threat' bypassed all wards!"
        }
    }
}

oo::class create FireWall {
    superclass Ward
    method handle {threat} {
        if {$threat eq "FlameVirus"} {
            puts "FireWall neutralized $threat."
        } else {
            next $threat
        }
    }
}

oo::class create IceWall {
    superclass Ward
    method handle {threat} {
        if {$threat eq "CryoWorm"} {
            puts "IceWall shattered $threat."
        } else {
            next $threat
        }
    }
}

set w1 [FireWall new]
set w2 [IceWall new]
$w1 setNext $w2

$w1 handle "CryoWorm"
$w1 handle "ShadowTrojan"

The Chain of Responsibility

A monolithic defense is easily circumvented. Instead, we layer our wards like a string of cascading pearls. An incoming curse strikes the outer shell; if it is unrecognized, the event is cast deeper into the chain. TclOO’s next command makes this delegation feel like a natural flow of mystical current.

Runic Tags: #behavioral #chain of responsibility #filtering #events