Funkcja interfejsu Golang
type MathInterface interface {
Added() int
Subtract() int
}
type Math struct {
x, y int
}
func (m *Math) Add() int {
return m.x + m.y
}
func (m *Math) Subtract() int {
return m.x - m.y
}
func main() {
data := Math{}
data.x = 5
data.y = 3
added := data.Add()
subtract := data.Subtract()
fmt.Println(added)
fmt.Println(subtract)
}
Restu Wahyu Saputra