Created
August 8, 2014 01:45
-
-
Save tenntenn/e86b4e1efb8353633a9c to your computer and use it in GitHub Desktop.
埋め込みを他のパッケージから隠蔽する #golang ref: http://qiita.com/tenntenn/items/f636b68ba5260cac2c92
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
type Fuga struct { | |
} | |
type Hoge struct { | |
*Fuga | |
} |
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
// パッケージ外からもアクセスできる | |
hoge := &Hoge{&Fuga{}} | |
hoge.Fuga = nil |
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
type fuga struct { | |
} | |
type Hoge struct { | |
*fuga | |
} | |
func NewHoge() *Hoge { | |
return &Hoge{&fuga{}} | |
} |
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
// パッケージ外からはアクセスできない | |
hoge := pkg.NewHoge() | |
hoge.fuga = nil |
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
type Fuga struct { | |
} | |
type fuga Fuga | |
type Hoge struct { | |
*fuga | |
} | |
func NewHoge() *Hoge { | |
return &Hoge{&fuga{}} | |
} |
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
type stringer fmt.Stringer | |
type Hoge struct { | |
stringer | |
} | |
func NewHoge(s fmt.Stringer) *Hoge { | |
return &Hoge{stringer(s)} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment