4 ms·
What do you think about most object-oriented languages only allowing one definition of a method per class?
by reikonomusha 5y ago
What do you think about most object-oriented languages only allowing one definition of a method per class?
- lmm 5y agoIt's infuriating when it means you can't implement the same interface in two ways.
- Joker_vD 5y agoWell, how do you chose which implementation will get picked? In my experience, explicit wrappers is the cleanest way ― but then again, I also find explicit casts/conversions (which essentially are the same thing) to be the cleanest way too.
- lmm 5y agoIf it would be ambiguous then you would have to specify yes. But for the cases where the required type means there's only one implementation that could work, I don't see the value in having to specify.
- Joker_vD 5y agoUh, how would such an interface look? The one that can be implemented in two ways, and yet "the required type means there's only one implementation that could work"?
- lmm 5y agoI'm mainly thinking of parameterized interfaces, like `Comparable` or some kind of "Keyed<T>". Another example would be datastructures that can be iterated in multiple ways, e.g. a multidimensional array that can implement both `Iterable<Int>` and `Iterable<Row<Int>>` or something like that. You could have cases where you're passing that to a function that expects Iterable<Int> so it's obvious which implementation you want, and cases where you would have to disambiguate.
- silon42 5y agoSame interface? Or two interfaces with the same method signature?