The Bridge Hex
Decoupling abstraction from implementation in pure expressions.
✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Bridge
ARCANUM SCHOOL: Transmutation // Pure Environment Hexes
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// CODEX INCANTATION //
let
# Implementations (The Backend Systems)
linuxEnv = { buildCommand = "make linux"; };
darwinEnv = { buildCommand = "make darwin"; };
# Abstractions (The Frontend Interfaces)
# The abstraction holds a reference to the implementation (the bridge)
standardSpell = impl: {
cast = "Executing standard build: ''${impl.buildCommand}";
};
empoweredSpell = impl: {
cast = "Executing empowered build with superuser rights: sudo ''${impl.buildCommand}";
};
in
{
linuxStandard = (standardSpell linuxEnv).cast;
darwinEmpowered = (empoweredSpell darwinEnv).cast;
}
By passing the implementation as an argument to the abstraction, the Bridge pattern prevents a Cartesian explosion of variations. This approach is highly useful when managing multiple platforms (Linux, Darwin) across various operational profiles.
Runic Tags:
#structural
#bridge
#nix
#decoupling