[Types-sig] QueryProtocol

Paul Prescod paulp@ActiveState.com
Fri, 23 Mar 2001 13:24:23 -0800


Michel Pelletier wrote:
> 
> > Just to clarify, when I mean *BOTH*, I mean if either
> > of the following is true, then ClassX implements InterfaceY
> > is true:
> >
> >    (a) ClassX is declared to implement InterfaceY
> >    (b) InterfaceY decides that ClassX is an implementer.
> >
> > It's bi-directional, "or" style.
> 
> Mmm are you sure that's a good idea?  An interface is a contract, and (a)
> is a good idea because class X is making a contract with the user
> described in InterfaceY.  But in (b), you are assuming that the object has
> a contract.  That's bad.  Would you want someone to just "assume" that you
> are obligated to act a certain way under a certain contract without you
> explicitly declaring that?

If InterfaceY's implementor thinks they know what they are doing, we
trust them. That's the Python Way. Python gives you a lot of rope to
hang yourself -- by design! InterfaceY may have been invented precisely
to unify a set of classes that do not know about each other but have the
right interface. 

If a third party says that InterfaceY and Class X are compatible, we
should trust them too. Probably the "right way" for the third party to
say this is to inform either the interface or the class.

Python doesn't provide any "safety" anyhow, so if someone really wants
to say that class X implements interface Y, they can just hack class X's
__implements__. The question is whether there should be a more
structured, explicit way to do that. I think that there should be.

-- 
Take a recipe. Leave a recipe.  
Python Cookbook!  http://www.activestate.com/pythoncookbook