[Zope3-dev] Interface declaration API

Jim Fulton jim@zope.com
Tue, 11 Mar 2003 16:38:21 -0500


Gary Poster wrote:
> 
> 
> Jim Fulton wrote:
> 
>> Phillip J. Eby wrote:
>>
>>> I'm also curious whether the default interface spec for a class' 
>>> instances should perhaps be the union of the interfaces specified by 
>>> __bases__, rather than flat inheritance in __mro__-first order.
> 
>  >> ...snip...
> 
>>
>> There are several choices:
>>
>> A. Don't inherit anything
>>
>> B. Inherit the first set of declarations you find, if any
>>
>> C. Inherit everything
>>
>> D. Inherit what you say
>>
>> Currently, we implicitly do B because:
>>
>> - It's a compromise betwee A and C, and
>>
>> - It's the easiest to implement.
>>
>> My preference (ignoring implementation issues) would be to inherit
>> nothing implicitly and to make it relatively easy to say you inherit
>> everything.
>>
>> Most people would prefer to inherit everything by default.
>> I've had to discuss this so many times that I'm getting worn down. :)
>>
>> Subclassing is done to reuse implementation. If interfaces were
>> inherited, then you would be unable to subclass a class without
>> also promising to implement the base class interfaces.  I've always
>> viewed this as an undesireable requirement, but maybe I'm wrong,
>> since so many people desire it, ;) So I'm willing to give on this.
> 
> 
> FWIW, I'd greatly prefer what you prefer, Jim.  At one point, and maybe 
> now, the event and object hub services code used this distinction, I 
> believe.

Meaning that they subclassed a class without satisfying the base class'
interface?

>  > ...snip...
>  > I'll call YAGNI on doesNotImplement.
> 
> However, if the "inherit everything" behavior does become the default, 
> this would no longer be a YAGNI, I think.

It would be a yagni, because implements would have this meaning. In::

  class A:
    implements(IA)

  class B(A): pass

  class C(A):
     implements(IC)

Instances of A and B have the IA interface, but instances of C have only the
IC interface.

Jim


-- 
Jim Fulton           mailto:jim@zope.com       Python Powered!
CTO                  (888) 344-4332            http://www.python.org
Zope Corporation     http://www.zope.com       http://www.zope.org