Hash: SHA1

Chris Withers wrote:
> Philipp von Weitershausen wrote:
>>   >>> IZopeDublinCore(obj)
>> is a flexible version of
>>   >>> ZDCAnnotatableAdapter(obj)
>> Flexible, because a different implementation that ZDCAnnotatableAdapter 
>> might be used. That's dispatched through the adapter registry.
> Right, exactly.
>>> IZopeDublinCore(myobj) does an adapter lookup based on the type of 
>>> 'myobj' 
>> That's the lookup in the registry (part 1 of the adapter call)
>>> and returns an adapter instance with myobj as context, ready to be used.
>> That's the instantiation a la str(123) (part 2 of the adapter call)
> Ah, I think this is becoming clearer...
> So, as another example, I could register the following as a factory for 
> turning instances of DateTime instances into datetime instances:
> def convert_dates(date):
>     return datetime(year=date.Year(),month=date.Month(),day=date.Month())
> The important thing here, for me, is that the adapted value is not an 
> instance of the adapter factory.

Factories return objects -- that's what they are for.  If you register a
class as an adapter factory (which the vast bulk of Zope3 applications
do) then the adapter returned by the factory will be an instance of that
class, because calling the class gives you an instance.  Note that in
the terms used in Zope3, the *returned object* is the adapter:  the
callable is the thing which *makes* adapters.

Any callable which takes the appropriate number of arguments can be
registered as a factory:  the only contract is that the return value
from the callable is supposed to implement the interface for which the
factory was registered.  The only (current) exception is "subscription
adapters", which are registered for 'None' rather than an interface:
their return value is *ignored*, because they do all their work when called.

We were discussion a (notional) "value adapter", whose factory would
have the contract of returning an object of a specific concrete type,
rather than on implementing an interface.  There are reasonable usecases
for such adapters, but the CA machinery doesn't permit registering them:
 it requires that the 'provided' argument be either an interface or None
(although the 'required' args can be concrete types).

Hope that clarifies, rather than confuses, the discussion.

- --
Tres Seaver          +1 202-558-7113          [EMAIL PROTECTED]
Palladion Software   "Excellence by Design"    http://palladion.com
Version: GnuPG v1.4.2.2 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

Zope3-dev mailing list
Unsub: http://mail.zope.org/mailman/options/zope3-dev/archive%40mail-archive.com

Reply via email to