The Strategy
Swapping algorithms for artifact synthesis dynamically.
✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Strategy
ARCANUM SCHOOL: Divination // Tactical Planning
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// STARLARK PATTERN //
def fast_build_strategy(srcs):
return ["fast_compile: " + s for s in srcs]
def optimized_build_strategy(srcs):
return ["heavy_compile: " + s for s in srcs]
def build_project(srcs, strategy_func):
# The core context delegates the actual synthesis to the injected strategy
print("Preparing workspace...")
artifacts = strategy_func(srcs)
return artifacts
# Usage
debug_mode = True
active_strategy = fast_build_strategy if debug_mode else optimized_build_strategy
outputs = build_project(["core.c", "math.c"], active_strategy)
The Strategy pattern leverages Starlark’s support for first-class functions. Instead of nesting deep if/else statements to handle debug versus release builds, the Archmage simply passes the desired compilation algorithm as a function pointer to the core rule. This isolates the tactical algorithmic logic from the structural workspace preparation, ensuring that new strategies can be invoked without modifying the primary invocation spell.
Runic Tags:
#behavioral
#starlark
#hermetic