The Flyweight
Use sharing to support large numbers of fine-grained logical assertions efficiently.
✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Flyweight
ARCANUM SCHOOL: Transmutation // Efficiency
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// ISABELLE PATTERN //
theory Flyweight
imports Main
begin
datatype particle_type = FireSpark | IceShard
record flyweight_particle =
ptype :: particle_type
shared_texture :: string
definition particle_factory :: "particle_type \<Rightarrow> flyweight_particle" where
"particle_factory pt = (case pt of
FireSpark \<Rightarrow> \<lparr> ptype = FireSpark, shared_texture = ''red.png'' \<rparr>
| IceShard \<Rightarrow> \<lparr> ptype = IceShard, shared_texture = ''blue.png'' \<rparr>)"
end
Runic Tags:
#isabelle
#hol
#transmutation
#design-patterns