The Abstract Factory
A pure functional approach to the Abstract Factory pattern in Gleam.
✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Abstract Factory
ARCANUM SCHOOL: Conjuration // Type-Safe Alchemy
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// GLEAM PATTERN //
pub type ElementalTheme {
Fire
Water
}
pub type Staff {
FireStaff(power: Int)
WaterStaff(flow: Int)
}
pub type Robe {
FireRobe(defense: Int)
WaterRobe(ward: Int)
}
pub type AbstractForge {
AbstractForge(
create_staff: fn() -> Staff,
create_robe: fn() -> Robe,
)
}
pub fn get_forge(theme: ElementalTheme) -> AbstractForge {
case theme {
Fire -> AbstractForge(
create_staff: fn() { FireStaff(10) },
create_robe: fn() { FireRobe(5) },
)
Water -> AbstractForge(
create_staff: fn() { WaterStaff(8) },
create_robe: fn() { WaterRobe(7) },
)
}
}
The Abstract Factory
In the Beam Machine, factories are merely records of pure functions that conjure elements of the same elemental affinity.
Runic Tags:
#conjuration
#factory
#gleam