Created
February 26, 2012 17:50
-
-
Save aquilax/1917943 to your computer and use it in GitHub Desktop.
Go Interface working sample
This file contains 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 Common struct { | |
s string | |
} | |
type Object interface { | |
GetCommon() (*Common) | |
} | |
type Test struct{ | |
c *Common | |
} | |
func (t *Test) GetCommon() (*Common) { | |
return t.c | |
} | |
func Show(o Object) { | |
fmt.Println(o.GetCommon().s) | |
} | |
func NewCommon(text string) (*Common){ | |
return &Common{text} | |
} | |
func main(){ | |
c := NewCommon("test") | |
t := Test{c} | |
Show(&t) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment