Skip to content

Instantly share code, notes, and snippets.

@mizchi
Created August 1, 2010 12:03
Show Gist options
  • Select an option

  • Save mizchi/503285 to your computer and use it in GitHub Desktop.

Select an option

Save mizchi/503285 to your computer and use it in GitHub Desktop.
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