Skip to content

Instantly share code, notes, and snippets.

@arriqaaq
Created January 27, 2023 09:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arriqaaq/f87fd019150d3d9e30e672b968de3c09 to your computer and use it in GitHub Desktop.
Save arriqaaq/f87fd019150d3d9e30e672b968de3c09 to your computer and use it in GitHub Desktop.
package pizza
type Pizza interface {
GetPrice() float64
GetDescription() string
}
type Margherita struct{}
func (m *Margherita) GetPrice() float64 {
return 10.0
}
func (m *Margherita) GetDescription() string {
return "Margherita"
}
type ToppingDecorator struct {
Pizza Pizza
}
func (t *ToppingDecorator) GetPrice() float64 {
return t.Pizza.GetPrice()
}
func (t *ToppingDecorator) GetDescription() string {
return t.Pizza.GetDescription()
}
type Cheese struct {
*ToppingDecorator
}
func (p *Cheese) GetPrice() float64 {
return p.ToppingDecorator.GetPrice() + 2
}
func (p *Cheese) GetDescription() string {
return p.ToppingDecorator.GetDescription() + ", Cheese"
}
type Mushroom struct {
*ToppingDecorator
}
func (m *Mushroom) GetPrice() float64 {
return m.ToppingDecorator.GetPrice() + 1.5
}
func (m *Mushroom) GetDescription() string {
return m.ToppingDecorator.GetDescription() + ", mushroom"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment