4 ms·
"What we really want is a flattened struct" That's what we call struct embedding. Check this http://talks.golang.org/2014/go4java.slide#33 http://talks.golang
by campoy 12y ago
"What we really want is a flattened struct"
That's what we call struct embedding.
Check this http://talks.golang.org/2014/go4java.slide#33 http://talks.golang.org/2014/go4java.slide#33 for more details.
- sat 12y agoEmbedding won't give you a flattened structure with transparency you expect. In other words struct B embedded in struct A will only create a syntactic sugar so that you can access properties of B through A. It won't work in other cases .Check this out - http://stackoverflow.com/questions/24333494/golang-reflection-on-embedded-structs http://stackoverflow.com/questions/24333494/golang-reflectio... This is not to say inheritance is better. I am just illustrating how reuse is harder with go because it expects a lot more code to do a simple thing.