The Abstract Factory Pattern
A protocol-oriented conjuration for orchestrating families of related orchard enchantments without specifying their concrete implementations.
â§ GANG OF FOUR LINEAGE & ARCANUM â§
GOF DESIGN PATTERN: Abstract Factory
ARCANUM SCHOOL: Conjuration // Orchardmancy
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// SWIFT PATTERN //
protocol AppleEnchantment {
func cast() -> String
}
protocol TreeEnchantment {
func cast() -> String
}
protocol OrchardFactory {
func createAppleEnchantment() -> AppleEnchantment
func createTreeEnchantment() -> TreeEnchantment
}
class PoisonAppleEnchantment: AppleEnchantment {
func cast() -> String { return "Casting poison on the apple..." }
}
class PoisonTreeEnchantment: TreeEnchantment {
func cast() -> String { return "Blighting the tree..." }
}
class DarkOrchardFactory: OrchardFactory {
func createAppleEnchantment() -> AppleEnchantment { return PoisonAppleEnchantment() }
func createTreeEnchantment() -> TreeEnchantment { return PoisonTreeEnchantment() }
}
The Abstract Factory: Orchard Conjuration
In the mystical groves of Apple programming, the Abstract Factory is a protocol-oriented spell. It allows a magus to summon related families of enchantmentsâsuch as those affecting apples and treesâwithout binding their spellbooks to concrete incantations.
Using Swiftâs powerful protocols, we define the essence of the enchantments. Concrete factories, such as the DarkOrchardFactory, provide the specific implementations.
Runic Tags:
#swift
#design-pattern
#creational