It definitely works differently to C++/Java/Python, but IMO this is one place where Rust is a huge improvement. You are effectively always generic over an interface (trait in Rust) rather than a base class, and this is much more flexible as a given strict can implement as many interfaces as it likes rather than being stuck in one class hierarchy (or having to deal with the pain of multiple inheritance)
It is no different than using interfaces, protocols, pure virtual base classes....
It's similar, but there are some differences. Notably, my package can implement my trait for your type, while my package (usually? always?) cannot make your type inherit from my virtual base class.
Depends on the flexibitly of the language, there isn't a golden way to do that across all variations of OOP.
Wrapper classes should be equally good once Valhalla (jdk) lands, without introducing another pointer indirection.
Interesting but Java gets more and more complex in a way that does not make me want to write things in Java.
Re:How I went about learning Rust
by pentachoron on Friday July 15, 2022 @05:42AM
(#32106390)
Not a Rust expert but: doesn't Rust support this use-case via Box<dyn SomeTrait> , and leveraging default Trait methods, only overriding the defaults you want to for each type implementing the Trait?
I mostly use OOP when I have a bunch of Foos and Bars, and want to treat them differently in some places. Instead of having ifs in each function, I use inheritance, and override the methods that I want to treat differently. It's mostly about heterogenous containers and avoiding explicit ifs. When you use it that way, it's safe and convenient and I've never ran into the fragile base class problem or other typical issues.