The Visitor Intrusion
Separate an algorithm from the object structure on which it operates.
✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Visitor
ARCANUM SCHOOL: Evocation // Intrusion
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// PHP PATTERN //
<?php
namespace Tekromancy\WebChaos;
interface Component {
public function accept(Visitor $visitor): void;
}
class EntityA implements Component {
public function accept(Visitor $visitor): void { $visitor->visitEntityA($this); }
public function exclusiveMethodA(): string { return "A"; }
}
interface Visitor {
public function visitEntityA(EntityA $element): void;
}
class ChaosExporter implements Visitor {
public function visitEntityA(EntityA $element): void {
echo "Exporting chaos: " . $element->exclusiveMethodA() . "\n";
}
}
The Visitor Intrusion
Adding operations to deeply entrenched legacy structures risks invoking the Elephant’s Curse across the codebase. The Visitor pattern acts as a phantom intrusion, walking across the object graph and operating upon the nodes without requiring any structural changes to the nodes themselves.
Runic Tags:
#web-chaos-magic
#elephants-curse
#php8