[Zope-dev] Re: [Zope] RE: [Zope-dev] manage_afterAdd and manage_beforeDelete

Jim Fulton jim@digicool.com
Mon, 12 Jul 1999 16:46:52 -0400


Brian Lloyd wrote:
> 
> It probably a bad idea to try to use manage_afterAdd
> as a handy constructor - the manage_afterAdd and manage_beforeDelete
> methods are currently a lightweight solution for the fact that
> there is no "event model" in Zope, but often objects will want
> to perform some extra activities when they are added/deleted
> (such as add or remove themselves from Catalogs).
> 
> The manage_afterAdd, in particular, could get you in trouble,
> since it will also be called whenever an object cut/copied and
> pasted to a new location. In that case the construction logic
> would almost certainly not be appropriate, and could actually
> run without raising an error, but re-initializing and wiping out
> the existing data in your object in the process. :(
> 
> In general, the manage_afterAdd and manage_beforeDelete protocol
> should be thought of as hooks for fixing up or cleaning up the
> environment of an object on add/delete/cut/copy/paste events
> (registering and unregistering with Catalogs, etc.).

To reinforce your point, these hooks
should absolutely not be conected with constructors in any way.
Adding an object is not like creating it.  These hooks are for objects
that modify their environment and, therefore, need to know when 
they've been inserted into or removed from an environment. Most objects
should not modify their environments and should not need these methods.

Jim

--
Jim Fulton           mailto:jim@digicool.com   Python Powered!        
Technical Director   (888) 344-4332            http://www.python.org  
Digital Creations    http://www.digicool.com   http://www.zope.org    

Under US Code Title 47, Sec.227(b)(1)(C), Sec.227(a)(2)(B) This email
address may not be added to any commercial mail list with out my
permission.  Violation of my privacy with advertising or SPAM will
result in a suit for a MINIMUM of $500 damages/incident, $1500 for
repeats.