Factory Method in ReasonML
Deferring instantiation to variant matchers.
✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Factory Method
ARCANUM SCHOOL: Conjuration // Summoning
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// REASON PATTERN //
type spell = Fireball | Frostbolt;
let cast = (s: spell) =>
switch (s) {
| Fireball => "Summoning flames..."
| Frostbolt => "Chilling the air..."
};
Instead of classical inheritance, the Factory Method relies on the sacred variant types and pattern matching to conjure the correct implementation.
Runic Tags:
#reason
#factory-method
#creational