🎯 DART SPELLS DIFFICULTY: Adept Behavioral

The Leyline Chain

Pass a magical request along a chain of wards until one resolves it.

✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Chain of Responsibility
ARCANUM SCHOOL: Abjuration // Warding
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// DART PATTERN //
abstract class Ward {
  Ward? _next;

  void setNext(Ward ward) => _next = ward;

  void handleAttack(int power) {
    if (canDeflect(power)) {
      print('${runtimeType} deflected the attack of power $power!');
    } else if (_next != null) {
      print('${runtimeType} failed. Passing to next ward...');
      _next!.handleAttack(power);
    } else {
      print('All wards breached. You take $power damage!');
    }
  }

  bool canDeflect(int power);
}

class ShieldCharm extends Ward {
  @override
  bool canDeflect(int power) => power <= 10;
}

class AegisField extends Ward {
  @override
  bool canDeflect(int power) => power <= 50;
}

class VoidBarrier extends Ward {
  @override
  bool canDeflect(int power) => power <= 100;
}

void main() {
  final chain = ShieldCharm()
    ..setNext(AegisField()
      ..setNext(VoidBarrier()));

  chain.handleAttack(45);
  chain.handleAttack(150);
}

When a chaotic attack hits your system, you shouldn’t hardcode exactly which defense triggers. You construct a chain of Wards. Each ward inspects the incoming anomaly; if it cannot handle the payload, it channels it down the leyline to the next defender.

Runic Tags: #dart #chain-of-responsibility #middleware #abjuration