Created
August 1, 2010 12:03
-
-
Save mizchi/503285 to your computer and use it in GitHub Desktop.
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
| package main | |
| import "fmt" | |
| //interface | |
| type AllowedMethods interface{ | |
| produce() | |
| set(s string) | |
| } | |
| func produce(inf AllowedMethods){ inf.produce() } | |
| func set(inf AllowedMethods,s string){ inf.set(s) } | |
| //structure | |
| type Obj struct { | |
| title string | |
| internal InternalObj | |
| } | |
| type InternalObj struct { a,b int} | |
| func (o Obj) produce() { fmt.Println( "My name is "+ o.title) } | |
| func (o *Obj) set(s string) { o.title = s } | |
| func main() { | |
| obj := new(Obj) | |
| // 直接 | |
| obj.set("Mizchi") | |
| obj.produce() | |
| println((obj.internal.a +3)) | |
| // interfaceを介したアクセス | |
| set(obj,"bar") | |
| produce(obj) | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment