The Visitor Astral Projection
Representing an operation to be performed on the elements of an object structure without modifying the classes.
✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Visitor
ARCANUM SCHOOL: Divination // Projection
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// FSHARP PATTERN //
// In F#, the Visitor pattern is usually replaced by Discriminated Unions and Pattern Matching
type ArcaneStructure =
| Obelisk of power: int
| LeylineNode of active: bool
| ManaFont of capacity: int
// The 'Visitor' function
let analyzeStructure (structure: ArcaneStructure) =
match structure with
| Obelisk p -> printfn "Analyzing Obelisk. Power level: %d" p
| LeylineNode a -> printfn "Analyzing Leyline. Is active: %b" a
| ManaFont c -> printfn "Analyzing Mana Font. Capacity: %d" c
let structures = [
Obelisk 100
LeylineNode true
ManaFont 500
]
structures |> List.iter analyzeStructure
The traditional Visitor pattern relies on double-dispatch and heavy interface coupling. The F# magus bypasses this entirely using Discriminated Unions and Pattern Matching, allowing the Astral Projection to analyze structures securely and elegantly without invading their OOP definitions.
Runic Tags:
#behavioral
#visitor
#fsharp
#projection