The Bridge
Decoupling abstractions from implementations via function injection.
✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Bridge
ARCANUM SCHOOL: Transmutation // Planar Binding
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// GLEAM PATTERN //
pub type CastingFocus {
Wand
Staff
}
pub type Spell {
Spell(
name: String,
cast_impl: fn(CastingFocus) -> String
)
}
pub fn cast_spell(spell: Spell, focus: CastingFocus) -> String {
spell.cast_impl(focus)
}
The Bridge
By passing first-class functions, we decouple the spell’s abstraction from its material implementation.
Runic Tags:
#transmutation
#bridge
#gleam