What is the best way to program over "abstract" types in D?

Ola Fosheim Grøstad ola.fosheim.grostad at gmail.com
Sat Nov 23 11:21:32 UTC 2019


One advantage of using abstract OO superclasses is that you can 
implement a lot of functionality on the superclass and save 
yourself some work when implementing concrete subclasses. 
However, virtual functions can be slow. In Rust you can do the 
same with "traits", but statically.

What is the best way to create generic interfaces with generic 
implementations of algorithms in D that works with structs (so 
you don't have to require Heap allocation with classes)?

I imagine one way to do it is using mixins in the concrete types, 
then the "abstract type" would essentially emerge as duck-typing. 
But that is really doing it on the wrong level and it is easy to 
make mistakes, so the typing becomes weak.

What would the best pattern in D be for doing statically resolved 
OO, with abstract super types that specify behaviour, over 
structs?



More information about the Digitalmars-d-learn mailing list