30 lines
404 B
Go
30 lines
404 B
Go
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!"
|
|
}
|