[Zope3-dev] Re: Creating new objects in a package

Peter Mayne PeterMayne at ap.spherion.com
Mon Sep 27 01:47:59 EDT 2004


Stephan Richter wrote:
> On Thursday 23 September 2004 21:23, Peter Mayne wrote:
> 
>>I was experimenting with the createObject() method described in section
>>9.4, which seemed to be recommended. If creating an object is this easy,
>>why bother with createObject() and factories?
> 
> First of all, factories are often not just the class. In fact, they commonly 
> are not the class. Often they are a function that puts a security proxy 
> around the object, once it is created. See the 'zope:content' directive 
> handler to see what I am talking about.

Fair enough, but I've read nothing about this in the book so far. (I 
haven't read it all, so I may very well have missed something.) The book 
offers createObject() as a way of creating objects, with no obvious 
alternatives, and no real explanation of how to use it: no docstring, 
looking at the source isn't very helpful, and how do I create a factory 
in the first place? And then it turns out I don't need it after all, 
which turns out to be much simpler. :-)

So, when *do* I need a factory? Why do I need a security proxy around an 
object? Why doesn't such a seemingly important method as createObject() 
have any docstring at all? (Rhetorical questions for now: the answers 
should be elsewhere.)

>>Having now just created a new object, I've tried to rename it:
>>
>>         msg = self.context['msg1']
>>         del self.context['msg1']
>>         self.context['msg2'] = msg
>>
>>which didn't work.
> 
> Mmmh, this should have worked, since it calls all the necessary code. 

I was getting a "no such attribute as '__parent__'" error or somesuch. 
After playing with a different problem which ended up at the same error, 
I ended up subclassing my implementation from 
zope.app.container.contained.Contained, which I suspect would solve this 
problem as well.

>>On a hunch, a "grep -r rename" found  zope.app.copypastemove.rename which 
> 
> does the trick, 
> 
> You see, the book fulfilled its goal. It empowered you enough so that you can 
> find and understand things yourself.

:-)

I've been empowered to do that for a long time. :-) On the other hand, I 
don't see that in the "Goals of this book" section. :-)

>>but the Handbook doesn't mention this anywhere. 
> 
> Right. I do not think programming-based copy and move are such common 
> operations that it is worth mentioning in the book.

On the contrary, it's because they are common operations that it's all 
the more important that they should be mentioned. Where else am I going 
to find out about them? Really.

>>Even sadder, rename() doesn't even have a 
>>docstring. (Yes, I know it's obvious in this case, but its the principle
>>of the thing. :-)
> 
> 
> The documentation of rename is really in the ObjectMover class. But please 
> feel free to add some documentation to the rename() function itself for 
> clarity.

It's not in the class docstring. And how am I supposed to know that 
there is an ObjectMover class that has a rename() method? Is it 
mentioned in any documentation?

>>A low-level fundamentals chapter in the Handbook would be very
>>informative.
> 
> 
> Could you list a set of topics that you would consider fundamental? I think 
> part C & D talk about the fundamental steps already.

Having read the parts of the book I need to read, my impression is that 
this book describes the use of the Z3 framework to develop applications, 
and does a pretty reasonable job. However, things below the level of the 
framework such as creating, managing, and deleting objects don't get 
mentioned. Arguably, this kind of stuff should come with the Z3 
distribution. On the other hand, I'm a developer, and I'm reading a 
developer's handbook, and (certainly in my case) it's a reasonable 
assumption that I'm ignorant of Z3. Even after reading the book, I don't 
see how I could write bugtracker's bug importer, because I still 
wouldn't know how to create my own IBug objects.

How about a chapter called "Zope 3 API" which goes through some of the 
basic non-framework subjects? How do I manipulate objects? What the heck 
is IContained for? ...

>>Or is there somewhere else that this kind of stuff is 
>>documented, along with things like "how do I pack my Data.fs": do I
>>really have to write my own Application Control (chapter 35)?
> 
> 
> It is correct that I originally developed this control for the book. However, 
> it was also intended to go into the Zope core as soon as I was done, where it 
> is now. I just believe in using useful and real-world examples to show how 
> something can be accomplished.

Excellent, but where is it documented? Again, the book is about the Z3 
framework, not management of a Z3 instance, so I wouldn't necessarily 
expect to find out about packing Data.fs in there, but it would be nice 
to find such things somewhere. I presume the documentation exists 
somewhere, but I just haven't found it yet.

I totally agree with your use of useful and real-world examples, and I'm 
not implying that this a bad example, I just want to know how to do 
fundamental management tasks.

> Regards,
> Stephan

Thanks for the assistance.

PJDM
-- 
Peter Mayne
Spherion Technology Solutions
Canberra, ACT, Australia
"You're given the form, but you have to write the sonnet yourself.
What you say is completely up to you." - Mrs. Whatsit



More information about the Zope3-dev mailing list