Documentation
¶
Overview ¶
Package visitor implements the Visitor design pattern. The Encounterer interface defines the common interface for all visitors (heroes) that can interact with various elements (monsters) that implement Confronter interface. The double dispatch mechanism is achieved through the Confront method, allowing each hero and monster combination to define unique interaction logic. In this implementation, different types of heroes (Encounterers) enter a haunted house and confront various supernatural creatures (Confronters).
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Confronter ¶
type Confronter interface {
Confront(v Encounterer)
Hit(strength int)
IsAlive() bool
fmt.Stringer
}
Confronter defines the common interface for all elements that can be confronted by Encounterers (visitors). It provides methods for engaging in combat, taking damage, reporting their state, and checking whether they are still alive.
type Demon ¶
type Demon struct {
// contains filtered or unexported fields
}
Demon represents a powerful infernal creature that thrives on chaos and fire. Highly resistant to physical attacks; faith-based assaults are most effective.
func (*Demon) Confront ¶
func (d *Demon) Confront(v Encounterer)
Confront allows the Demon to face an Encounterer through double dispatch.
type Encounterer ¶
type Encounterer interface {
FaceGhost(v Confronter)
FaceDemon(v Confronter)
FaceVampire(v Confronter)
FaceZombie(v Confronter)
FaceWitch(v Confronter)
fmt.Stringer
}
Encounterer defines the common interface for all visitors that can interact with different Confronters using double dispatch.
type Extendable ¶
type Extendable interface {
Add(participant any) Extendable
}
Extendable defines the ability to add new participants into a composite structure (Encounterers and Confronters).
type Ghost ¶
type Ghost struct {
// contains filtered or unexported fields
}
Ghost represents an ethereal, floating spirit with limited ectoplasmic energy. Immune to bullets and blades, but weak to scientific gadgets and faith.
func (*Ghost) Confront ¶
func (g *Ghost) Confront(v Encounterer)
Confront allows the Ghost to face an Encounterer through double dispatch.
type GhostBuster ¶
type GhostBuster struct{}
GhostBuster is a modern hero who relies on gadgets and proton technology. Extremely effective against Ghosts; less so against physical foes.
func (*GhostBuster) FaceDemon ¶
func (g *GhostBuster) FaceDemon(v Confronter)
FaceDemon allows the GhostBuster to interact with the Demon Confronter.
func (*GhostBuster) FaceGhost ¶
func (g *GhostBuster) FaceGhost(v Confronter)
FaceGhost allows the GhostBuster to interact with the Ghost Confronter.
func (*GhostBuster) FaceVampire ¶
func (g *GhostBuster) FaceVampire(v Confronter)
FaceVampire allows the GhostBuster to interact with the Vampire Confronter.
func (*GhostBuster) FaceWitch ¶
func (g *GhostBuster) FaceWitch(v Confronter)
FaceWitch allows the GhostBuster to interact with the Witch Confronter.
func (*GhostBuster) FaceZombie ¶
func (g *GhostBuster) FaceZombie(v Confronter)
FaceZombie allows the GhostBuster to interact with the Zombie Confronter.
func (*GhostBuster) String ¶
func (g *GhostBuster) String() string
String returns the stringified name of the GhostBuster.
type HauntedHouse ¶
type HauntedHouse struct {
// contains filtered or unexported fields
}
HauntedHouse represents a collection of Confronters—monsters that can be encountered by a Party of Encounters. It provides methods for adding Confronters, initiating encounters, and displaying the results of battles.
func NewHauntedHouse ¶
func NewHauntedHouse() *HauntedHouse
NewHauntedHouse creates the new Haunted House with Confronters.
func (*HauntedHouse) Add ¶
func (h *HauntedHouse) Add(enemy any) Extendable
Add allows to add the Confronter in the House.
func (*HauntedHouse) Visit ¶
func (h *HauntedHouse) Visit(party *Party)
Visit allows a Party of Encounterers to confront all Confronters within the HauntedHouse. Each hero sequentially faces the enemies, and the final battle results are displayed afterward.
type Party ¶
type Party struct {
Heroes []Encounterer
}
Party is the composite for the Encounterers party, with the ability of adding to party and printing the information about it.
func (*Party) Add ¶
func (p *Party) Add(hero any) Extendable
Add allows to add the Encounterers to the Party.
type Priest ¶
type Priest struct{}
Priest represents a holy Encounterer who uses faith and ritual to fight evil. His abilities are most effective against Demons and Vampires, less so against Zombies or Witches.
func (*Priest) FaceDemon ¶
func (p *Priest) FaceDemon(v Confronter)
FaceDemon allows the Priest to interact with the Demon Confronter.
func (*Priest) FaceGhost ¶
func (p *Priest) FaceGhost(v Confronter)
FaceGhost allows the Priest to interact with the Ghost Confronter.
func (*Priest) FaceVampire ¶
func (p *Priest) FaceVampire(v Confronter)
FaceVampire allows the Priest to interact with the Vampire Confronter.
func (*Priest) FaceWitch ¶
func (p *Priest) FaceWitch(v Confronter)
FaceWitch allows the Priest to interact with the Witch Confronter.
func (*Priest) FaceZombie ¶
func (p *Priest) FaceZombie(v Confronter)
FaceZombie allows the Priest to interact with the Zombie Confronter.
type Soldier ¶
type Soldier struct{}
Soldier represents a disciplined fighter with raw firepower and tactical efficiency. Best suited for physical threats; struggles against ethereal beings.
func (*Soldier) FaceDemon ¶
func (s *Soldier) FaceDemon(v Confronter)
FaceDemon allows the Soldier to interact with the Demon Confronter.
func (*Soldier) FaceGhost ¶
func (s *Soldier) FaceGhost(v Confronter)
FaceGhost allows the Soldier to interact with the Ghost Confronter.
func (*Soldier) FaceVampire ¶
func (s *Soldier) FaceVampire(v Confronter)
FaceVampire allows the Soldier to interact with the Vampire Confronter.
func (*Soldier) FaceWitch ¶
func (s *Soldier) FaceWitch(v Confronter)
FaceWitch allows the Soldier to interact with the Witch Confronter.
func (*Soldier) FaceZombie ¶
func (s *Soldier) FaceZombie(v Confronter)
FaceZombie allows the Soldier to interact with the Zombie Confronter.
type Vampire ¶
type Vampire struct {
// contains filtered or unexported fields
}
Vampire represents an undead predator who feeds on the living. Weak against holy items, sunlight, and anyone carrying garlic.
func (*Vampire) Confront ¶
func (v *Vampire) Confront(hv Encounterer)
Confront allows the Vampire to face an Encounterer through double dispatch.
type VampireHunter ¶
type VampireHunter struct{}
VampireHunter specializes in exterminating vampires, but takes on other foes with variable success.
func (*VampireHunter) FaceDemon ¶
func (vh *VampireHunter) FaceDemon(v Confronter)
FaceDemon allows the VampireHunter to interact with the Demon Confronter.
func (*VampireHunter) FaceGhost ¶
func (vh *VampireHunter) FaceGhost(v Confronter)
FaceGhost allows the VampireHunter to interact with the Ghost Confronter.
func (*VampireHunter) FaceVampire ¶
func (vh *VampireHunter) FaceVampire(v Confronter)
FaceVampire allows the VampireHunter to interact with the Vampire Confronter.
func (*VampireHunter) FaceWitch ¶
func (vh *VampireHunter) FaceWitch(v Confronter)
FaceWitch allows the VampireHunter to interact with the Witch Confronter.
func (*VampireHunter) FaceZombie ¶
func (vh *VampireHunter) FaceZombie(v Confronter)
FaceZombie allows the VampireHunter to interact with the Zombie Confronter.
func (*VampireHunter) String ¶
func (v *VampireHunter) String() string
String returns the stringified name of the VampireHunter.
type Witch ¶
type Witch struct {
// contains filtered or unexported fields
}
Witch represents a cunning spellcaster skilled in curses and mischief. Difficult to kill, but vulnerable to precision and disbelief.
func (*Witch) Confront ¶
func (w *Witch) Confront(v Encounterer)
Confront allows the Witch to face an Encounterer through double dispatch.
type Zombie ¶
type Zombie struct {
// contains filtered or unexported fields
}
Zombie represents a reanimated corpse driven by hunger and confusion. Easy to kill, but is very interested in brains.
func (*Zombie) Confront ¶
func (z *Zombie) Confront(v Encounterer)
Confront allows the Zombie to face an Encounterer through double dispatch.