|
Posted by Oli Filth on 10/30/13 11:33
FluffyCat said the following on 30/11/2005 19:48:
> On 30 Nov 2005 08:35:22 -0800, "Oli Filth" <catch@olifilth.co.uk>
> wrote:
>>
>>Exactly; what's the point in calling Visitee->accept(Visitor), whose
>>only job is to call Visitor->visit(this)? If ObjectStructure has a
>>reference to both Visitor and Visitee, why doesn't it just call
>>Visitor->visit(Visitee)? This would make for a simpler, more intuitive
>>arrangement.
>>
>
> I'm not clear if you object to the Visitor pattern as it is generally
> accepted in the OO world, or only to my example of it.
I think I'd have to say that I "object" (a rather strong term, though ;)
) to your example, because it doesn't demonstrate any benefits that
arise from the double dispatch.
If you were treating $book and $software polymorphically within
testVisitor.php, then this would be a viable demonstration of the use of
double dispatch.
Alternatively, if your accept() methods were doing more than just
calling the visit() methods (i.e. actually performing some sort of
private operations inside the Visitee classes) then this would also
demonstrate some kind of "point" to an arrangement like this.
But as it stands, in testVisitor.php you're merely substituting a call
to $plainVisitor->visitBook($book) with a call to
$book->accept($plainVisitor), which is only likely to make people think
"Well, what's the point in that?".
--
Oli
Navigation:
[Reply to this message]
|