Prototype
Clone intricate celestial constellations using the Prototype pattern in Julia.
✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Prototype
ARCANUM SCHOOL: Illusion // Echoes
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// JULIA PATTERN //
# Prototype in Julia: Cloning Constellations
struct Star
name::String
magnitude::Float64
end
struct Constellation
name::String
stars::Vector{Star}
end
# In Julia, base copy logic works natively. We can override for deep copies.
import Base: copy
function copy(c::Constellation)
# Deep copy the stars for true prototype pattern behavior
cloned_stars = [Star(s.name, s.magnitude) for s in c.stars]
return Constellation(c.name * " (Echo)", cloned_stars)
end
# Usage
orion = Constellation("Orion", [Star("Betelgeuse", 0.42), Star("Rigel", 0.12)])
orion_clone = copy(orion)
Runic Tags:
#creational
#prototype
#julia
#astromancy