33 lines
448 B
Go
33 lines
448 B
Go
package main
|
|
|
|
import "fmt"
|
|
|
|
type bot interface {
|
|
getGreeting() string
|
|
}
|
|
|
|
type englishBot struct{}
|
|
type spanishBot struct{}
|
|
|
|
func main() {
|
|
eb := englishBot{}
|
|
sb := spanishBot{}
|
|
|
|
printGreetings(eb)
|
|
printGreetings(sb)
|
|
}
|
|
|
|
func printGreetings(b bot) {
|
|
fmt.Println(b.getGreeting())
|
|
}
|
|
|
|
func (englishBot) getGreeting() string {
|
|
// Very custom logic
|
|
return "Hello"
|
|
}
|
|
|
|
func (spanishBot) getGreeting() string {
|
|
// Very custom logic
|
|
return "Hola!"
|
|
}
|