Re:Inheritance was invented as a performance hack
by zozbot234 on Friday April 30, 2021 @06:28AM
(#26991711)
Traits are virtual dispatching, albeit the dispatch table is not bundled with the object. The meaningful distinction is between implementation inheritance vs. inheritance of interfaces, abstract classes or traits.
[ Parent
| on HN ]
Re:Inheritance was invented as a performance hack
by Twisol on Friday April 30, 2021 @11:31AM
(#26994743)
Trait objects (via `dyn`) are virtual dispatching, but traits themselves are basically agnostic to static vs. virtual dispatch. If you use a trait method through a statically known type, the method is invoked statically -- no runtime lookup.