|
Posted by FluffyCat on 10/27/14 11:33
Ok, excellent stuff to think about. The problem with doing these
examples is that there is a huge difference between getting your code
to run and having a good example of a pattern.
I did add a function to my testVisitor that will take in any Visitee
and Visitor and call $visitee->accept($visitor), and so adds a bit
more polymorphism to the mix.
I'm still not convinced this is necessary for a viable Visitor
example, but if it helps to make things seem at all clearer I'm
totally into it.
I would have preferred, as was suggested, to give the Visitor some
special access to Visitor. However, I don't see how to do this with
PHP. In C++ you can set up friend (?) classes. In Java you can have
package level access. As is stated in GoF, "the pattern often forces
you to provide public operations to access the element's internal
state, which may compromise it's encapsulation". I guess you could
say that Visitor Pattern is a way to add a new operation to a class
with out altering the class - but without the advantage of having any
special class access.
Navigation:
[Reply to this message]
|