foreach/opApply is the visitor pattern
Spacen Jasset
spacenjasset at yahoo.co.uk
Fri Feb 13 13:25:46 PST 2009
grauzone wrote:
> 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)
>
> More importantly, why does it matter?
Because there is a difference? opApply is more like a functor. Not the
visitor pattern in my view of things.
They are/can be used to solve different things.
The visitor pattern commonly can be used to avoid case object.type:
situations, to deal with different object types. Whereas a functor is
used for other things, like iteration.
More information about the Digitalmars-d-learn
mailing list