Skip to content

Instantly share code, notes, and snippets.

@Thrimbda
Created August 16, 2017 03:44
Show Gist options
  • Select an option

  • Save Thrimbda/bc0fba41e79b949a8d020782bd07bd8c to your computer and use it in GitHub Desktop.

Select an option

Save Thrimbda/bc0fba41e79b949a8d020782bd07bd8c to your computer and use it in GitHub Desktop.
this is a gist of golang's OOP.
// 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