λ SCHEME RUNE DIFFICULTY: Adept Structural

The Bridge

Decoupling ethereal abstraction from corporeal implementation.

✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Bridge
ARCANUM SCHOOL: Transmutation // Synthesis
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// SCHEME PATTERN //
(define (make-wand material-impl)
  (lambda (action)
    (case action
      ((channel) (material-impl 'glow))
      ((strike) (material-impl 'shatter)))))

(define (crystal-material)
  (lambda (msg)
    (case msg
      ((glow) "The crystal hums with blinding light.")
      ((shatter) "The crystal shatters into a thousand ethereal shards."))))

(define my-wand (make-wand (crystal-material)))
(my-wand 'channel)

Message-passing allows an abstraction (the wand) to seamlessly command its implementation (the material), separating the magic from the medium.

Runic Tags: #structural #scheme #message-passing