[Zope-dev] AttributeError validate using the Visitor pattern
R. David Murray
bitz@bitdance.com
Fri, 23 Feb 2001 11:35:05 -0500 (EST)
On Mon, 19 Feb 2001, Itai Tavor wrote:
> You posted your questions 3 days ago, so maybe you found a solution
> by now... but this might still be useful to you.
I just unwrapped the visitor pattern into an psuedo-case statement <grin>.
> - I'm passing _ explicitly instead of relying on binding. I vaguely
> recall reading something about a problem binding the namespace. It
> might be fixed in the latest Python Scripts, I haven't tried the CVS
> version yet.
This appeared to be the key. I changed my 'accept(me)' call to
read 'accept(me,_=_)', and everything started working. Thanks
very much!
> - visitLineItem is called in the context of an OrderLineItem, so no
> <dtml-with item> is needed.
I had actually tried that and gotten an even less intelligable error
message. So now I've reverted to that form and it works great.
> - If you wanted the visitor to implement looping over the items
> (which is how the GoF do it) you could easily make something like:
>
> Order.displayItemsVisitor.displayItems (DTML Method):
> <dtml-in line_items>
> <tr>
> <dtml-var "_['sequence-item'].accept(container, _)">
> </tr>
> </dtml-in>
Yeah, that's more or less what I do. My display dtml-method gets passed the
list of objects, and it does the loop (implementing the batching logic
for dtml-in) calling accept on the items in the list. I need to rename
my folder to make it's purpose clearer, though <grin>.
> BTW, I never thought of using a visitor for this until you brought it
> up, so thanks! What I really like about it is that the same 'accept'
> method can be used by multiple visitors, each one implementing a
> different view of the object. So I can have displayItemsVisitor,
> displayItemsCompactVisitor, and displayItemsEditableVisitor, all
Yeah, exactly. displayItemsEditableVisitor is why I chose to
implement the visitor pattern. I've wound up doing it another
way (checking the auth of the logged in user and putting in a button),
but I suspect I'll have another Visitor before I'm through with the
project.
Thanks again for your help.
--RDM