🔮 JULIA ASTROMANCY DIFFICULTY: Adept Creational

Factory Method

Forge arcane lenses through multiple dispatch with the Factory Method pattern in Julia.

✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Factory Method
ARCANUM SCHOOL: Conjuration // Celestial Forging
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// JULIA PATTERN //
# Factory Method in Julia: Forging Telescopes
abstract type DivinationLens end
struct OpticalLens <: DivinationLens end
struct AetherLens <: DivinationLens end

abstract type LensCrafter end
struct MundaneCrafter <: LensCrafter end
struct ArcaneCrafter <: LensCrafter end

forge_lens(::MundaneCrafter) = OpticalLens()
forge_lens(::ArcaneCrafter) = AetherLens()

function peer_into_void(crafter::LensCrafter)
    lens = forge_lens(crafter)
    println("Peering through a ", typeof(lens))
end

# Usage
crafter = ArcaneCrafter()
peer_into_void(crafter)
Runic Tags: #creational #factory #julia #astromancy