std.patterns: it was about time

Nick Sabalausky a at a.a
Sun Feb 1 12:09:29 PST 2009


"Michel Fortin" <michel.fortin at michelf.com> wrote in message 
news:gm45h5$6p1$1 at digitalmars.com...
>
> A general comment about the visitor pattern: if we had class extensions 
> where you could add new methods to Object, then the ability to add 
> overrides of those methods by extending various derived classes, you 
> wouldn't even need the visitor pattern. When you're used to that in 
> Objective-C, the visitor pattern feels like a clever but cumbersome 
> workaround for the lack of class extensibility.
>

I've never used Objective-C, but I had done a lot of C# (which also has 
extension methods) before I really looked into the visitor pattern, and that 
was pretty much my thought on the visitor pattern as well (ie, a cumbersome 
workaround). Although, there's two things about the visitor patten that I'm 
not certain would be taken care of by extension methods:

Multiple Dispatch: Although that could be overcome manually with RTTI.

Compositional Hierarchy (such as the car example): But I would think this 
could be handled by exposing an opApply or something like that.

Although, extension methods are really just syntactical sugar for a 
non-member (or static member) function call with a class as the first 
argument, so I'm not sure that even extension methods are strictly necessary 
to render the visitor pattern unneeded (But maybe there's something about 
the visitor pattern I'm not understanding.) 





More information about the Digitalmars-d mailing list