3 ms·
To be fair, anonymous fields in Go are essentially inheritance in disguise.
by comex 14y ago
To be fair, anonymous fields in Go are essentially inheritance in disguise.
- btilly 14y agoI would disagree. If you call a method that you have because of an anonymous field, and within that method you make a second method call, the second method call gets the method for the anonymous field's type, and not your type. Thus you can't override it. This is very different from how inheritance works in Smalltalk, Java, Python, Ruby, Perl, etc, etc, etc. In C++ terms their methods are all virtual, hence subclasses can override them. And such overriding is a central part of standard OO designs. Go's methods are not virtual.
- pcwalton 14y agoInheritance does not imply virtual methods. They are two different features. Even as early as Simula 67, virtual methods were not the default and had to be explicitly annotated.