4 ms·
> Can't even say something like "my custom button is a special kind of android button, with just those two methods being overriden". Of course you can do that
by burntsushi 12y ago
> Can't even say something like "my custom button is a special kind of android button, with just those two methods being overriden".
Of course you can do that in Golang. You don't need inheritance. It has composition with type embedding. You can even "override" methods.
http://play.golang.org/p/UV55gQj7t0 http://play.golang.org/p/UV55gQj7t0
- bsaul 12y agoI know you can, i've explicitly talked about struct inheritance in my comment, as well as manually defining functions for the new type. Yet, this is a weird construct if all you want to do is class inheritance. You have to deal with questions like "do i want to define the func on my type, or on a pointer to that type", or "how do i call "super"", how do i extend the constructor for that new type, etc.. All those questions do have answers in golang. But you have to learn new patterns in order to do an extremely basic and common thing in OOP, once again, without much immediate apparent benefit.
- burntsushi 12y ago> i've explicitly talked about struct inheritance in my comment It's not struct inheritance[1], so I wasn't sure what you were talking about. [1] - http://golang.org/ref/spec#Struct_types http://golang.org/ref/spec#Struct_types
- scottlamb 12y ago> You can even "override" methods. That's not the same thing as overriding a virtual method in an OO language. If B() calls A(), it gets the general A: http://play.golang.org/p/nu7kY168E9 http://play.golang.org/p/nu7kY168E9
- burntsushi 12y ago... hence the scare quotes ...