Visitor pattern revisited in D

Timon Gehr timon.gehr at gmx.ch
Tue Aug 28 08:39:06 PDT 2012


On 08/27/2012 05:00 PM, deadalnix wrote:
> /!\ Shameless autopromotion incoming /!\
>
> I have recently put some effort into exploring alternatives to visitor
> pattern and see what can be done in D. I ended up with a solution which
> is a real improvement compared to plein old visitor pattern and wanted
> to share this here.
>
> I think this is short enough to be a good example to show what can be
> done with D capabilities.
>
> http://www.deadalnix.me/2012/08/25/visitor-pattern-revisited-in-d/

An issue is that the proposed scheme does not support subclassing a
node to tweak its behaviour without changing the way the visitor
operates on it. i.e. it violates the substitution principle by default.

You can return void expressions from void functions, this is a
deliberate design decision to make generic code less noisy.

     static if(is(typeof(return) == void)) {
         unhandled(o);
     } else {
         return unhandled(o);
     }

==>

     return unhandled(o);




More information about the Digitalmars-d-announce mailing list