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

Jim Fulton jim at zope.com
Tue Sep 30 13:19:53 EDT 2003


Steve Alexander wrote:
> 
>> 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.

That's not fair. :)  All of the adapters need to be ranked. The idea is,
what would be the one you'd use if the favorite one wasn't there.

> * 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.

But, suppose that there is B3:

   class B3(B0): pass

and there's an adapter from F1 to B3?  How do you know that the adapter
from F1 to B1 or B2 is better than the one to B3.  It seems to me that,
given a better adapter, it would be a good idea to register it for the
base interfaces explicitly.  Perhaps there could be an easy way to spell
this.


>> 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.

Could you elaborate what "registering locally" should mean then?
I'm not sure what you are agreeing with?

> 
>> 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.

But I don't know what your idea of "registering locally" is.

Jim

-- 
Jim Fulton           mailto:jim at zope.com       Python Powered!
CTO                  (540) 361-1714            http://www.python.org
Zope Corporation     http://www.zope.com       http://www.zope.org




More information about the Zope3-dev mailing list