Created
December 5, 2010 10:31
-
-
Save drewlesueur/728999 to your computer and use it in GitHub Desktop.
The hello world of Object Oriented Prorgramming in Go
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
// run this code at http://golang.org/ | |
package main | |
import "fmt" | |
type Person struct { | |
age int | |
name, fav_band string | |
} | |
// the 'that' is like the 'this' you would see in other languages | |
func (that *Person) getOlder() int { | |
that.age = that.age + 1 | |
return that.age | |
} | |
func main() { | |
person := new(Person) | |
// or var person Person | |
person.age = 7 | |
fmt.Println(person.age) | |
person.getOlder() | |
fmt.Println(person.age) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks to tutorial at http://research.swtch.com/2009/12/go-data-structures-interfaces.html
Also see the aswesome functional programming tutorial at http://livingcode.org/2009/11/13/go-language-and-functional-programming.html
Any suggestions?