[Zope3-dev] Re: adaptation based on class rather than interface
Jean-Marc Orliaguet
jmo at ita.chalmers.se
Mon Nov 13 12:33:03 EST 2006
Lennart Regebro wrote:
> On 11/13/06, Jean-Marc Orliaguet <jmo at ita.chalmers.se> wrote:
>> Indeed technically yes. Practically not. I couldn't find many examples
>> in the zope3 codebase that adapts classes.
>> The #1 pattern is to adapt from interfaces, it appears as though there
>> is a reason for it.
>
> Yes, and I think both you and me mentioned it, but with different
> wordings.
>
> If you specify it for a class, then only that class is adaptable. If
> you want to use the adapter for yet another class, you have to
> register it again. This is possible, but it's more flexible to specify
> the adapter for an interface, and let all adaptable classes implement
> that interface.
>
yes, but if you register an adapter for a base class you don't have to
register it for subclasses, do you?
subclasses will pick up the same adapter. Provided that you use classes
for typing your objects and not interfaces.
otherwise I withdraw what I previously wrote (that classes were
adaptable) if that's for individual classes only. The basic force behind
adapter registration (based on interfaces) is the principle of inheritance.
> This is also a matter of specifying things for what they can do,
> instead of for what they are, which you mentioned.
>
> I'm not sure the proliferication (?) of marker interfaces is a big
> risk. But if we get many of them, it still works better than the
> options of magic __something__ attributes. :)
>
but conceptually it is the same mess :-) i.e. a total lack of
specification. It only looks nicer with interfaces.
/JM
More information about the Zope3-dev
mailing list