Created
January 27, 2023 09:47
-
-
Save arriqaaq/f87fd019150d3d9e30e672b968de3c09 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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