[Zope] Python object lifecycle? (was Re: [Zope] Where to put businesslogic?logic?

Jeff K. Hoffman jeff@goingv.com
Fri, 18 Feb 2000 14:14:46 -0500 (EST)


On Fri, 18 Feb 2000, Robb Shecter wrote:

> It looks like Zope's answer here is to write Python classes that get used as
> external methods.  What's not clear to me is how these Python objects live and
> die, and when.

Just thought I'd drop a quick note to say that, IMHO, external methods are
NOT the way to go, here.

External are targeted towards a limited problem domain, and have several
disadvantages. Chris Petrilli, in his "Zope for Developers" talk at IPC8,
discussed this issue briefly. The advantages of external methods, in his
slides are:

  - Familiar Python code-base.
  - Access to all Pythonisms and modules

While the disadvantages are:

  - Can be very unsafe
  - Ideological disconnect
  - Stored externally and not versioned.

External methods are great when you say, for instance, "I have everything
I need for this site EXCEPT I could really use an md5 hash of the user's
IP address when computing an identity cookie." You just make a
"compute_md5_hash" external method, implement it using Python's md5
capabilities, and acquire it into any site you want to use it in.

However, for something as complex as business rules, I would make a Python
product. This way you can build a complete class hierarchy if you need to,
calling into your Python instances from Zope and/or having Python call 
back into Zope. Any initialization can be done at Product load time in
__init__.py.

This all requires a little more Zope Zen than creating a few hundred
external methods, but you will fine the outcome much more safe,
understandable, and easy to maintain.

> - Robbb

--Jeff

PS. See Chris's slides at:

  http://www.zope.org/Members/petrilli/Presentations/IPC8/Developers.htm

---
Jeff K. Hoffman                                         704.849.0731 x108
Chief Technology Officer                                mailto:jeff@goingv.com
Going Virtual, L.L.C.                                   http://www.goingv.com/