[Zope3-Users] Re: Adapter lookup given object with multiple
candidate interfaces
Philipp von Weitershausen
philipp at weitershausen.de
Sun Sep 17 17:31:36 EDT 2006
George Lee wrote:
> If an object X implements both interfaces I1 and I2, how does an adapter Y which
> can either map from I1->I3 or I2->I3 determine Y(X)?
You got several things wrong here:
* things are adapted by calling an interface, e.g. I3(X), not Y(X)
* not the adapter determines the return value of the adaption, but the
adapter registry. I3(X) yields to an object that provides I3. The fact
that it's Y is due to the fact that you registered Y as an adapter for
I1 and I2.
* If an object X *provides* (which is different from "implements") I1
and I2 (in that order!), and you have an adapter from I1 to I3 and one
from I1 to I3, then the adapter that maps from I1 to I3 will be chosen
when you do I3(X). That's because X provides I1 first, then I2. The
order matters.
I suggest you read some docs on adaption.
http://worldcookery.com/Appetizers has a few.
Philipp
More information about the Zope3-users
mailing list