[Zope3-dev] Re: reasonable syntax for multi-adaptation

Tres Seaver tseaver at palladion.com
Wed Sep 26 21:05:46 EDT 2007


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Martijn Faassen wrote:
> Hey,
> 
> My opinions:
> 
> It'd be nice if getMultiAdapter's functionality was in reach without 
> typing: import zope.component; zope.component.getMultiAdapter. The 
> IFoo() single adapter lookup shows us a way to make this possible: a 
> method (in this case __call__ on the interface). It does bother me on 
> occasion that I need to invoke multi adaptation in such an entirely 
> different way. I must also note that it's a very common intuition to 
> want to do something like IFoo((a, b)).
> 
> Even though  my intuition is usually like Jim's and prefer to have two 
> different methods, given different semantics, I consider the differences 
>   in semantics here such a grey area I'm on the fence.
> 
> That the object itself is returned if it already provides the interface 
> in single adaptation is a difference in semantics,

The fact that the object may be returened as its own adapter is
logically opaque to the caller, who should properly care only that the
returned value implements the interface.  For exactly the same reason, I
think that calling an iterface with an *empty* context list could
reasonablly be construed as a 'getUtility' request:  the fact that a
factory is called for one, and not the other, is irrelevant *to the caller*.

> but since there's 
> just no possibility of doing so in the case of multi adaptation anyway, 
> you can argue whether this is a difference in semantics or not, just 
> some semantics that doesn't apply. __conform__ is a bigger difference, 
> but given that polymorphism abounds in object oriented code, having 
> different behavior with different inputs is not *that* surprising either.

Exactly.

> Anyway, if we want to split methods, I'm fine with a properly named 
> method for multi-adaptation on the interface. For completeness' sake 
> you'd also want a properly named method on the interface for 
> single-adaptation.
> 
> IFoo.adapt() for normal adaptation
> IFoo.multiadapt() for multi adaptation

I'd rather have 'adapt' take *args for the contexts, and keywords for
extras (like name).

> sound reasonable to me. We then explain that if you call IFoo directly, 
> IFoo.adapt is called. These could then also be extended to support named 
> adapter lookup and such.



Tres.
- --
===================================================================
Tres Seaver          +1 540-429-0999          tseaver at palladion.com
Palladion Software   "Excellence by Design"    http://palladion.com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFG+wHp+gerLs4ltQ4RAkyiAJ0biniCdvVIs5vgVCzSm1ISzbWF5QCfQ7FQ
iQsVQ0u8q1ZWg2UEGOx43qY=
=HlvT
-----END PGP SIGNATURE-----



More information about the Zope3-dev mailing list