by timtadh on 5/20/16, 6:40 PM with 7 comments
by echlebek on 5/20/16, 7:30 PM
by lobster_johnson on 5/20/16, 9:09 PM
type Foo struct {
...
}
type Bar struct {
Foo
}
...You can't pass Bar (or pointer to Bar) to anything that requires Foo (or pointer to Foo), even it looks like they'd have identical memory layouts and therefore be compatible, though that is exactly what inheritance aims to achieve in other OO languages.by spriggan3 on 5/20/16, 9:24 PM
There is no support for inheritance in Go, calling struct embedding inheritance is incorrect. Inheritance implies a type hierarchy, there is no type hierarchy in Go, types are flat. If you think you can mimick inheritance with struct embedding you're going to feel a whole lot of pain when you pass values around functions then expect boxing / unboxing types to work in like C# or Java.
by breerly on 5/21/16, 5:11 AM
It's a bit more like PHP's traits - https://secure.php.net/manual/en/language.oop5.traits.php
Ruby's mixins are a bit similar as well - http://culttt.com/2015/07/08/working-with-mixins-in-ruby/
Think of it as language-assisted copy paste.
by timtadh on 5/24/16, 1:08 AM