3 ms·
I personally don't like inheritance as it is implemented in Java/C++. To me it feels like terrible default way to design a language so that methods can be share
by mywittyname 6y ago
I personally don't like inheritance as it is implemented in Java/C++. To me it feels like terrible default way to design a language so that methods can be shared between structured data types. It's certainly useful in a lot of cases, but I don't think it is in the majority of cases.
Traits feel more natural to me. Instead of needing to make a subclass of a data structure to attach a foo method to it, you can define a collection of foo methods with the same name and pick the runtime implementation based on data structures passed to the method. I understand that this six of one, half dozen of the other, but I do prefer it this way.
Granted, this is not something OOP does "wrong," and you can use generics to accomplish a similar thing, so it's not that big of a deal.
- wvenable 6y agoInheritance is just traits combined interfaces. Interface is type, trait is the implementation. It just so happens that bringing the type along with the implementation is so common/useful that traits on their own aren't as common as inheritance.