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

Martijn Faassen faassen at startifact.com
Tue Dec 1 10:28:47 EST 2009


Martin Aspeli wrote:

> Can you summarise what you mean by this? The thread is so long...
[snip]
> My brain hurts... examples?
[snip]
> I'm afraid you've lost me. Four ways sounds bad, though. ;-)

I've edited down and clarified what I posted earlier.

First a statement about the goal of this discussion. The goal of this 
discussion is to convince people to unify the lookup API. I wouldn't 
want to make lookup API improvements depend on improvements to 
zope.component inspired by the discussion below. I'm in favor of 
exploring that in a separate project, however.

* abstract factory called on an object (adaptation)

    In: the requested interface, one ore more instances

    Process: look up factory. Call factory with input instances.

    Out: a new instance that provides requested interface

* abstract instance retrieval (utility lookup)

    In: the requested interface

    Process: look up instance.

    Out: a previously registered instance that provides requested interface.

* abstract factory not called on an object ("utility factory",
"null-adaptation")

    In: the requested interface

    Process: look up factory. Call factory.

    Out: a new instance that provides the requested interface

* abstract instance retrieval for an object ("utility associated with an
instance", "adapting to an existing instance")

    In: the requested interface, one or more instances.

    Process: look up instance with input instances as "context".

    Out: a previously registered instance that provides
the requested interface

The two latter patterns aren't fully supported. All of them could in 
principle be emulated using the "look up factory/call factory" pattern.

There are two perspectives on distinguishing adapters from utilities. 
One perspective is:

* newly created instance (adapter) versus previously registered instance 
(utility).

This perspective informs the "singleton" discussion. I'd say a better 
way to distinguish adapters from utilities (should we wish to do so) is:

* arguments into the factory (adapter) versus no arguments into the 
factory (utility)

That's inspired by the notion that adapters tend to have some form of 
abstract "connection" to what they adapt, while utilities do not.

Regards,

Martijn



More information about the Zope-Dev mailing list