The Bridge (jq)
Decouple the abstraction of an entity from its underlying elemental implementation.
✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Bridge
ARCANUM SCHOOL: Transmutation // Ethereal Connection
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// CODEX INCANTATION //
# Implementations
def render_html: "<div>" + .content + "</div>";
def render_markdown: "**" + .content + "**";
# Abstraction
def notification($renderer):
{
"id": .id,
"rendered_message": (.message | {content: .} | $renderer)
};
# Utilizing the Bridge
.events[] | notification(render_markdown)
The Bridge severs the bond between what an object represents and how its internals are executed. In the realm of jq, we pass filter functions as high-order arguments (the implementation) into the abstraction structure. This grants us the flexibility to swap rendering spells or processing protocols without mutating the core notification chassis.
Runic Tags:
#jq
#json
#transmutation
#gof