Visitor pattern revisited in D

deadalnix deadalnix at gmail.com
Tue Aug 28 17:24:57 PDT 2012


Le 28/08/2012 17:39, Timon Gehr a écrit :
> 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.
>

It does indeed. This is why I started by stating that we are interested 
in object as data abstraction here, not as behavioral one.

> 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);
>

unhandled isn't void. And typeof(return) isn't available at unhandled 
definition point.

That was my first short, but I couldn't make it work.


More information about the Digitalmars-d-announce mailing list