2 ms·
No, traits are not inheritance, nor is derive that is default implementation of some traits. Traits are like interfaces in OOP languages (simplified), the equi
by alerighi 4y ago
No, traits are not inheritance, nor is derive that is default implementation of some traits.
Traits are like interfaces in OOP languages (simplified), the equivalent of a class would be a struct + all the impls of that struct. And that thing cannot be extends, a struct is fixed when defined and nobody can extend it, you can use composition that is the correct to me way to go.
- queuebert 4y agoThat's why I said "flavor". It's not exactly inheritance obviously, but provides some of the same functionality. There are many ways to skin an OO cat. Traits describe the methods implemented, and you can override with specific implementations or inherit the default, from a level up.