[Zope-dev] summary of discussion was: adapter vs factory Re: implementing zope.component 4.0

Chris McDonough chrism at plope.com
Tue Dec 1 10:38:06 EST 2009


Chris McDonough wrote:
> On the semantics of the change:
> 
> Personally I think that it's a fantasy to believe that the difference between 
> an object created via a factory on-demand and an object simply returned should 
> *never* matter to a caller.  You may not want the caller to need to care, and 
> it may be inconvenient to take into account circumstances where the caller 
> needs to care.  But because this is Python, the caller still often does need to 
> care.
> 
> The only circumstance where a caller would *never* need to care would be when 
> the object returned could be guaranteed to *never ever* have any methods called 
> on it that weren't part of the interface defined by the interface being looked 
> up.  If we want this, we should probably just be using Java.

I'll retract this.

If you want to create a world where callers never need to care about the 
lifetime of any object returned by a component lookup, you could also return a 
proxy wrapper around the returned object that only allows for the invocation of 
the methods defined in the interface looked up.  Any other access or invocation 
would raise an exception.

This would make this worldview 100% consistent, completely documentable, and 
would cause no confusion during use.  It would thus remove any logical argument 
I have against it.  I wouldn't be eager to use such a system, but it's totally 
consistent.

- C



More information about the Zope-Dev mailing list