Skip to content

Instantly share code, notes, and snippets.

@tubbo
Created June 11, 2020 01:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tubbo/3a1bd82d652e473897267d22eed51dea to your computer and use it in GitHub Desktop.
Save tubbo/3a1bd82d652e473897267d22eed51dea to your computer and use it in GitHub Desktop.
package main
type Addable interface {
Total int
Add(value int) int
}
func (addable *Addable) Add(value int) int {
addable.Total = addable.Total + value
return addable.Total
}
type Order struct {
Total int
}
func main() {
order := &Order{ Total: 0 }
order.Add(1)
fmt.Println(order.Total)
}
package main
type Addable interface {
Total int
Add(value int) int
}
func (addable *Addable) Add(value int) int {
addable.Total = addable.Total + value
return addable.Total
}
type Order struct {
Total int
}
func (order *Order) Add(value int) int {
if value <= 3 {
addable.Total = addable.Total + value
}
return addable.Total
}
func main() {
order := &Order{ Total: 0 }
order.Add(1)
fmt.Println(order.Total)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment