30 lines
404 B
Go
Raw Normal View History

2022-02-12 00:22:02 +01:00
package main
import "fmt"
type bot interface {
getGreeting() string
}
type englishBot struct{}
type spanishBot struct{}
func main() {
eb := englishBot{}
sb := spanishBot{}
printGreeting(eb)
printGreeting(sb)
}
func printGreeting(b bot) {
fmt.Println(b.getGreeting())
}
func (englishBot) getGreeting() string {
return "Hi there!"
}
func (spanishBot) getGreeting() string {
return "Hola!"
}