[Zope3-dev] Ranking adapters (2nd try)

Steve Alexander steve at z3u.com
Tue Sep 30 12:52:56 EDT 2003


> Now, suppose that we need an adapter from F1 to B0.
> We can use any of the adapters above.  How would we rank
> the above adapters?  I suggest:
> 
>   A212
>   A110
>   A111
>   A112
>   A200

I worked this out on my own piece of paper before reading your suggested 
results.

I got:

   A212
   A111
   A110
   A200

Here's my rationale:

* A112 disappears because it is a registration for exactly the same 
from->to as A212.

* I put A111 before A110 because B1 is more specific than B0. A B1 can 
do all of what a B0 can do. Liskov substitutably etc.

Here's an example. Ignoring locations for a moment.

Let's say B0 is ISized. It has methods for the sortable size with units 
and the human-readable size of something.

Let's say B1 is IComparablySized. It has a compare(another_ISized) method.

Let's say B2 is IComparablySizedWithUnitsConversion. It adds an optional 
'units' attribute to the getHumanReadableSize() from ISized.


Let's say someone sends me an ISized adapter that is vastly improved 
over the default for IFoo objects. The default for IFoo objects is just 
an ISized. However, this improved version is an 
IComparablySizedWithUnitsConversion.

When I register this new adapter, do I register it for only F1 -> B2, or 
do I register it for F1 -> {B2,B1,B2} ?

I suggest that these should be equivalent. Registering F1 -> B2 should 
be equivalent to registering F1 -> B2, F1 -> B1, F1 -> B0, and even F1 
-> Interface.


> The most important factor is the interface being adapted.
> The second most important factor is location.
> The third most important factor is the interface being adapted to.

I agree.
I think I have a different idea of what "registering locally" should mean.

I think my idea of what "registering locally" should mean offers the 
kind of guarentees that Shane notes as important in his kiosk example.


> If we want a B, we don't really care much whether we get a B, a B1,
> or a B2.  It's fairly important to be able to override things locally,
> but it's not as important as getting an adapter tailored to the object.

I think my idea of "registering locally" fits with this.

--
Steve Alexander




More information about the Zope3-dev mailing list