The Chain of Responsibility for Spell Requests
Avoid coupling the sender of a request to its receiver by giving more than one object a chance to handle the request in Move.
✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Chain of Responsibility
ARCANUM SCHOOL: Abjuration // Bureaucracy
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// CODEX INCANTATION //
module arcane::chain_of_responsibility {
struct Request has drop {
level: u8,
handled: bool,
}
public fun create_request(level: u8): Request {
Request { level, handled: false }
}
public fun apprentice_handler(req: &mut Request) {
if (!req.handled && req.level <= 1) {
req.handled = true;
}
}
public fun mage_handler(req: &mut Request) {
if (!req.handled && req.level <= 5) {
req.handled = true;
}
}
public fun archmage_handler(req: &mut Request) {
if (!req.handled) {
req.handled = true;
}
}
}
Runic Tags:
#behavioral
#chain-of-responsibility
#move
#handlers