4 ms·
I don't know, and I never mentioned inheritance without polymorphism, so I don't see how its relevant. Go supports both inheritance and polymorphism. It just d
by bheadmaster 3y ago
I don't know, and I never mentioned inheritance without polymorphism, so I don't see how its relevant.
Go supports both inheritance and polymorphism. It just doesn't have polymorphic inheritance, which doesn't really bring you any new abilities that polymorphism and inheritance themselves didn't bring.
Please see this comment for an example of Go's polymorphism and inheritance working together to do what you would need virtual methods for in C++: https://news.ycombinator.com/item?id=35784598 https://news.ycombinator.com/item?id=35784598
- JonChesterfield 3y ago> Nobody said that inheritance must be polymorphic Polymorphim normally means dispatch based on type of the first argument to a function, sometimes called a method. Occasionally dispatch based on type of all arguments to a function. Inheritance is a means of deriving types from other types. That's usually done as a means of controlling dispatch via the above polymorphism. I don't know of a different motive for inheritance. You claimed inheritance doesn't need to be polymorphic, as quoted above, so I hoped you had a different perspective on it.
- bheadmaster 3y ago> I don't know of a different motive for inheritance. Code reuse? You have a base class that does a bunch of stuff, and you want to add a single thing. If there wasn't any motive for inheritance without polymorphism, then all methods in C++ would be virtual, wouldn't they?