The Composite
Compose objects into tree structures to represent part-whole hierarchies.
✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Composite
ARCANUM SCHOOL: Conjuration // Swarm-shaping
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// EXECUTABLE GO PATTERN //
package composite
import "fmt"
// Component
type MilitaryUnit interface {
ExecuteCommand()
}
// Leaf
type Skeleton struct {
Name string
}
func (s *Skeleton) ExecuteCommand() {
fmt.Println(s.Name + " strikes with rusty sword!")
}
// Composite
type NecromancerPlatoon struct {
Units []MilitaryUnit
}
func (n *NecromancerPlatoon) Add(unit MilitaryUnit) {
n.Units = append(n.Units, unit)
}
func (n *NecromancerPlatoon) ExecuteCommand() {
fmt.Println("Platoon executing commands...")
for _, unit := range n.Units {
unit.ExecuteCommand()
}
}
The Composite
A true necromancer commands armies, not just individuals. The Composite pattern treats a vast, hierarchical swarm of thralls identical to a single undead minion. Send a command to the platoon node, and the psychic link cascades downward, activating every skeleton, lich, and ghoul in perfect, terrible synchronization.
Runic Tags:
#Structural
#Conjuration
#Go