Created
December 7, 2010 05:31
-
-
Save drewlesueur/731506 to your computer and use it in GitHub Desktop.
polymorphism 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
//the terms "late binding", "dynamic binding", "polymorphism" kind of blur together for me | |
//here is an example of this concept in Go | |
package main | |
import "fmt" | |
type Animal interface { | |
Say() | |
} | |
type Dog struct { | |
} | |
func (d *Dog) Say() { | |
fmt.Println("Bark") | |
} | |
func test(a Animal) { | |
a.Say() | |
} | |
func main() { | |
dog := new(Dog) | |
test(dog) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment