22 ms·
I don’t know about Rust, but interfaces as in Java (or things like protocols in Objective-C) are fundamentally object-oriented features. It is at the core of th
by kergonath 2y ago
I don’t know about Rust, but interfaces as in Java (or things like protocols in Objective-C) are fundamentally object-oriented features. It is at the core of the concept. Java is much more object-oriented than C++.
You can do something similar with overloaded functions and functions interface, at which point you’re re-implementing OOP without encapsulation and worse language support.
- josephg 2y agoIt’s certainly not a feature that is exclusive to OO languages. Haskell supports type classes which can do the same thing. Or ocaml’s module types. Rust traits. Etc. I don’t think anyone will accuse those languages of being object oriented. Frankly C++’s abstract superclasses have, in my opinion, the worst syntax of them all to support the same feature. I really don’t see this kind of polymorphism as a weakness of non-OO languages. If you wanna play “who wore it better”, Haskell and rust get my vote. Rust traits are strictly more powerful than Java interfaces since you can say things like impl MyTrait for T where T: Iterator<…> {}