go interface
类型1:eFace = {类型,地址}
类型2:iFace={{t *iTab},地址}
// ==============
type Animal interface {
Speak() string
}
// ==============
type Dog struct {
}
func (d Dog) Speak() string {
return "Woof!"
}
// ==============
type Cat struct {
}
func (c Cat) Speak() string {
return "Meow!"
}
// ==============
type JavaProgrammer struct {
}
func (j JavaProgrammer) Speak() string {
return "Design patterns!"
}
// +++++++++++++++++++++++++++++++++
func main() {
animals := []Animal{Dog{}, Cat{}, Llama{}, JavaProgrammer{}}
for _, animal := range animals {
fmt.Println(animal.Speak())
}
}