Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

To be fair, anonymous fields in Go are essentially inheritance in disguise.


I 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.


Inheritance 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.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: