The Chain of Responsibility
Passing the primordial burden down a sequence of arcane handlers.
✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Chain of Responsibility
ARCANUM SCHOOL: Enchantment // Compulsion
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// B PATTERN //
/* Handlers are linked lists of function pointers and next pointers */
/* Node: [handler_func, next_node] */
handle_fire(req, next) {
if (req == 'FIRE') putchar('F');
else if (next) (next[0])(req, next[1]);
}
handle_ice(req, next) {
if (req == 'ICE') putchar('I');
else if (next) (next[0])(req, next[1]);
}
resolve() {
auto ice_node[2];
auto fire_node[2];
ice_node[0] = handle_ice;
ice_node[1] = 0; /* Null terminator */
fire_node[0] = handle_fire;
fire_node[1] = ice_node; /* Point to ice node */
/* Send burden down the chain */
(fire_node[0])('ICE', fire_node[1]);
}
Runic Tags:
#b
#design-pattern
#precursor
#bell-labs-magic
#untyped