The Flyweight
Conserving magical energy by sharing immutable soul-fragments.
✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Flyweight
ARCANUM SCHOOL: Transmutation // Essence Conservation
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// OCAML PATTERN //
module SoulForge = struct
let cache = Hashtbl.create 16
let get_fragment essence =
match Hashtbl.find_opt cache essence with
| Some frag -> frag
| None ->
let frag = "Fragment of " ^ essence in
Hashtbl.add cache essence frag;
frag
end
The Flyweight pattern conserves ethereal resources by utilizing a hash table to memoize and share immutable essence fragments across the realm.
Runic Tags:
#Caml Metamagic
#Memoization
#OCaml