Created
August 16, 2017 03:44
-
-
Save Thrimbda/bc0fba41e79b949a8d020782bd07bd8c to your computer and use it in GitHub Desktop.
this is a gist of golang's OOP.
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
| // this is a gist of golang's OOP. | |
| package main | |
| import "fmt" | |
| const ( | |
| Male = iota | |
| Female | |
| ) | |
| func main() { | |
| person := Person{"Thrimbda", Male} | |
| person.walk(100) | |
| } | |
| type Person struct { | |
| name string | |
| gender int | |
| } | |
| func (p Person) walk(distance int) { | |
| var prefix string | |
| if p.gender == Male { | |
| prefix = "Mr." | |
| } else { | |
| prefix = "Ms." | |
| } | |
| fmt.Printf("%s %s walked %d miles", prefix, p.name, distance) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment