foreach/opApply is the visitor pattern
grauzone
none at example.net
Sun Feb 1 09:49:37 PST 2009
BCS wrote:
> Hello Robert,
>
>> BCS wrote:
>>
>>> Correct me if I'm wrong but I thing that D's opApply is a form of the
>>> Visitor pattern where the calling function's stack frame is the
>>> visitor object.
>>>
>>> This just occurred to me. Maybe I've been missing something re the
>>> visitor pattern but I think this make for a nice, cool and easy way
>>> to describe it. (Also I don't remember it being described that way)
>>>
>> Er.... no. There's no double-dispatch (at least automatically),
>> there's only one foreach body delegate. The visitor pattern as far as
>> I know it uses dynamic dispatch so the visitor object can handle
>> different objects in the class hierarchy differently. For example, you
>> couldn't use a foreach to enumerate through a syntax tree and handle
>> expressions and statements differently (well, you could, but you'd
>> have to do it manually).
>>
>
> OK I'll grant that it doesn't follow the normal pattern to the letter
> but it can be viewed as a degenerate case where there is only one
> visitable type.
Does that mean all function calls are a degenerate case of the visitor
pattern?
More information about the Digitalmars-d-learn
mailing list