How to implement inheritance-like feature for Rust?

Inheritance constrains what you can do a lot more than traits.
Especially single inheritance becomes complicated when you start getting multiple "logical" baseclasses.
E.g. if you want to store all your stuff in a database, everything could `extends DatabaseObject". But then you later add a base class for formatting, and another base class for logging..

You eventually end up with one "god class" as base, that does way too many things (violates single responsibility principle), or your class hierarchy becomes incredibly complex, rigid and hard to refactor.

If you have shared logic in Rust, you can always put it in helper functions, because unlike Java, functions are a first class citizen (you can have "free" functions, without a class)

The "Behavioural Modelling" koan says it better than I ever could:

8 Likes