Re:How I went about learning Rust
by nicoburns on Friday July 15, 2022 @06:48AM
(#32106790)
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)
[ Parent
| on HN ]
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.