[Zope3-dev] Re: Basic Interfaces question

Jim Washington jwashin at vt.edu
Mon Jun 7 12:22:49 EDT 2004


Tres Seaver wrote:

> Jim Washington wrote:
>
>> Philipp von Weitershausen wrote:
>>
>>> Jim,
>>>
>>> > Let's say we have an interface IFoo and an interface IFooExtended
>>> >
>>> > IFoo defines foo as
>>> >
>>> > def foo():
>>> >    """do foo"""
>>> >
>>> > IFooExtended defines foo as
>>> >
>>> > def foo(myParam=None)
>>> >    """do the same thing as foo in IFoo, except use myParam to extend
>>> > behavior if available"""
>>> >
>>> > should IFooExtended descend from IFoo, or should IFooExtended be a
>>> > different interface?
>>> >
>>> > i.e., should the definition of IFooExtended be
>>> >
>>> > class IFooExtended(IFoo):
>>>
>>> Usually you would subclass the IFoo interface, but it really depends on
>>> the meaning you attach to IFooExtended. Are things that are 
>>> IFooExtended
>>> also IFoo? Judging by the name IFooExtended, I would think so, but it
>>> depends on the meaning you want to give it.
>>>
>> Yes, IFooExtendeds would also be IFoos; the question is whether the 
>> optional parameter makes foo() a sufficiently different interface to 
>> necessitate a complete interface definition. I presume that 
>> implementation classes could implement both. Are there technical 
>> reasons that a minor interface extension like this would make 
>> redefinition desirable?
>
>
> From a practical perspective, the extra argument won't be usable by 
> other components unless they can safely test for your extension; 
> defining the new interface makes that test safe and sane.
>
> In addition, it might let you register different components for the 
> extension, should that matter.

So, I'm guessing the pattern for this should be

class IFooExtended(IFoo):
    """Foo Interface with a small difference"""

    def fooExtended(myParam)
        """ do foo function with myParam; foo defined in IFoo but 
accepts no params"""

Then in an implementation class, have both foo and fooExtended functions.

This should work, and would not have the redefinition problem.

Thanks. 

-- Jim Washington



More information about the Zope3-dev mailing list