Abstract functions in child classes

Timon Gehr timon.gehr at gmx.ch
Fri Dec 2 13:19:21 PST 2011


On 12/02/2011 09:27 PM, Adam wrote:
> So this pattern allows you to provide partial implementations of an
> abstract, and use template specialization to provide a sort of
> "multiple inheritance" rather than strict class definition /
> extension. That's important in Scala because of the lack of multiple
> inheritance (as I understand it).
>
> Am I understanding this correctly - that the point of this approach is
> to replicate composition by multiple inheritance?

You can do that, but templates provide you with a lot more power. Note 
that some of my examples cannot be expressed as nicely in terms of 
multiple inheritance. That is because they rely on the order in which 
the classes are composed. This is sometimes discouraged in Scala afaik. 
I think, because there the type of an object does not depend on the 
trait mixin order. (not an issue here)

Parameterizing on the base class has quite some applications, its 
applications in C++ even have an own wikipedia page:

http://en.wikipedia.org/wiki/Curiously_recurring_template_pattern


More information about the Digitalmars-d-learn mailing list