Last active
August 29, 2015 14:05
-
-
Save simplyvikram/9c8a1d6d41844c06d25a to your computer and use it in GitHub Desktop.
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 Asset interface { | |
AssetType() string | |
GetBase() Base | |
SetBase(b Base) | |
} | |
type Base struct { | |
X int | |
} | |
type Article struct { | |
Base | |
} | |
func (a *Article) AssetType() string { | |
return "article" | |
} | |
func (a *Article) GetBase() Base { | |
return a.Base | |
} | |
func (a *Article) SetBase(b Base) { | |
a.Base = b | |
} | |
func ChangeAsset(a Asset) { | |
var b Base = a.GetBase() | |
b.X = 43 | |
a.SetBase(b) | |
} | |
func main() { | |
fmt.Println("Hello, playground") | |
var x Asset = &Article{Base: Base{5}} | |
ChangeAsset(x) | |
fmt.Println("Value of asset", x) | |
//a := b.(Article) | |
//fmt.Println(a.AssetType()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment