Source File: ex23/main.go
package main
import (
"fmt"
)
type Printer interface {
Print()
}
type Animal struct {
Name string
Age int
Species string
Weight float64
}
type Fruit struct {
Name string
Taste string
Smell string
}
func (what Animal) Print() {
fmt.Println("-- Animal named", what.Name)
fmt.Println(what.Name, "is", what.Age, "years old.")
fmt.Println(what.Name, "is a", what.Species)
fmt.Println(what.Name, "weighs", what.Weight)
}
func (what Fruit) Print() {
fmt.Println("-- Fruit named", what.Name)
fmt.Println(what.Name, "tasts like", what.Taste)
fmt.Println(what.Name, "smells like", what.Smell)
}
func PrintThing(out Printer) {
out.Print()
}
func main() {
joey := Animal{"Joey", 3, "Kangaroo", 100.0}
PrintThing(joey)
durian := Fruit{"Durian", "Heaven", "Dead bodies and onions."}
PrintThing(durian)
}