Documentation
¶
Overview ¶
Package decorator implements the Decorator design pattern. In the role-playing game example, we have three character classes: Knight, Magician, and Horseman. Each character has predefined attributes represented by the Character struct. Decorators such as WithPotion, WithShield, and WithSword enhance a character's abilities. These decorators can be applied in a composable manner, allowing for dynamic stacking of enhancements without modifying the original character implementation.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Buff ¶
type Buff interface {
Effectiveness() uint8
}
Buff defines the interface for all of the characters' decorators.
type Character ¶
Character is the common struct of all RPG characters.
func NewHorseman ¶
func NewHorseman() *Character
NewHorseman is a factory function that creates a new horseman.
func NewKnight ¶
func NewKnight() *Character
NewKnight is a factory function that creates a new knight.
func NewMagician ¶
func NewMagician() *Character
NewMagician is a factory function that creates a new magician.
type WithPotion ¶
type WithPotion struct {
Actor
}
WithPotion is the character's decorator for enhanced speed.
func UsePotion ¶
func UsePotion(a Actor) *WithPotion
UsePotion is the factory function for the WithPotion decorator.
func (*WithPotion) Effectiveness ¶
func (d *WithPotion) Effectiveness() uint8
Effectiveness returns the effectiveness number of the Buff.
type WithShield ¶
type WithShield struct {
Actor
}
WithShield is the character's decorator for enhanced defense.
func EquipShield ¶
func EquipShield(a Actor) *WithShield
EquipShield is the factory function for the WithShield decorator.
func (*WithShield) Effectiveness ¶
func (d *WithShield) Effectiveness() uint8
Effectiveness returns the effectiveness number of the Buff.
type WithSword ¶
type WithSword struct {
Actor
}
WithSword is the character's decorator for enhanced attack.
func EquipSword ¶
EquipSword is the factory function for the WithSword decorator.
func (*WithSword) Effectiveness ¶
Effectiveness returns the effectiveness number of the Buff.