The Bridge
Decouple an abstraction from its implementation so that the two can vary independently.
β§ GANG OF FOUR LINEAGE & ARCANUM β§
GOF DESIGN PATTERN: Bridge
ARCANUM SCHOOL: Transmutation // Dimensional-binding
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// EXECUTABLE GO PATTERN //
package bridge
// Implementor
type Enchantment interface {
Apply(damage int) string
}
// ConcreteImplementor1
type FireEnchantment struct{}
func (f *FireEnchantment) Apply(damage int) string {
return "burns for extra fire damage"
}
// ConcreteImplementor2
type FrostEnchantment struct{}
func (f *FrostEnchantment) Apply(damage int) string {
return "chills the target, slowing them"
}
// Abstraction
type Weapon interface {
Attack() string
}
// RefinedAbstraction
type Sword struct {
Damage int
Enchantment Enchantment
}
func (s *Sword) Attack() string {
effect := s.Enchantment.Apply(s.Damage)
return "Sword strikes and " + effect
}
The Bridge
To hardcode an enchantment onto a specific weapon type leads to endless, unmanageable armories. The Bridge pattern slices the structure in twoβthe physical construct (the abstraction) and the magical overlay (the implementor). Now, a blade can shift its elemental alignment on the fly, keeping the weapon matrix lightweight and deadly.
Runic Tags:
#Structural
#Transmutation
#Go