Created
June 8, 2014 12:47
-
-
Save tmtk75/cb4564665fd2308a9a70 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "fmt" | |
type Human struct { | |
Age int | |
Name string | |
Walk func(place string) | |
} | |
func (h Human) String() string { | |
return fmt.Sprintf("%s[%d]", h.Name, h.Age) | |
} | |
func (h Human) Run(distance int) { | |
fmt.Printf("%s run %dm\n", h, distance) | |
} | |
func (h Human) Dash(distance int) { | |
fmt.Printf("%s dash %dm\n", h, distance) | |
} | |
type Runner interface { | |
Run(distance int) | |
Dash(distance int) | |
} | |
func Goal(r Runner) { | |
r.Run(10) | |
r.Dash(50) | |
} | |
type Kid struct { | |
Human | |
School string | |
} | |
type Athlete interface { | |
Runner | |
} | |
func main() { | |
a := Human{Age: 10} | |
b := Kid{Human{Age: 20}, School: "Jingu"} | |
Goal(a) | |
Goal(b) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
$ go run mixture-of-field.go # command-line-arguments ./mixture-of-field.go:44: mixture of field:value and value initializers