🔮 JULIA ASTROMANCY DIFFICULTY: Adept Structural

Flyweight

Render sprawling starfields with minimal memory cost in Julia using the Flyweight pattern.

✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Flyweight
ARCANUM SCHOOL: Conjuration // Dimensional Compression
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// JULIA PATTERN //
# Flyweight in Julia: Rendering the Night Sky

# Intrinsic state (shared)
struct StarType
    color::String
    temperature::Float64
end

# The Flyweight Factory
const STAR_TYPES = Dict{String, StarType}()

function get_star_type(color::String, temp::Float64)
    key = color * string(temp)
    if !haskey(STAR_TYPES, key)
        STAR_TYPES[key] = StarType(color, temp)
    end
    return STAR_TYPES[key]
end

# Extrinsic state (unique)
struct PlacedStar
    x::Float64
    y::Float64
    z::Float64
    star_type::StarType
end

function draw_star(star::PlacedStar)
    println("Drawing star at (", star.x, ", ", star.y, ") with color ", star.star_type.color)
end

# Usage
blue_giant = get_star_type("Blue", 25000.0)

# Both stars share the same intrinsic StarType memory
star1 = PlacedStar(1.0, 2.0, 3.0, blue_giant)
star2 = PlacedStar(4.0, 5.0, 6.0, blue_giant) 

draw_star(star1)
draw_star(star2)
Runic Tags: #structural #flyweight #julia #astromancy