[Zope3-Users] question about a constraint conflict

FB fbo2 at gmx.net
Sat Jan 6 14:51:07 EST 2007


Hi,

On Sat, Jan 06, 2007 at 01:35:35AM +0100, Christophe Combelles wrote:
> Hello
> 
> I define the following interfaces:
> 
> class IFoo(Interface):
>   pass
> class IBar(Interface):
>   pass
> 
> class IFooContainer(IContainer):
>   contains(IFoo)
> class IBarContainer(IContainer):
>   contains(IBar)
> 
> Then I would like to configure a class Test to to be both a FooContainer and a BarContainer:
> 
> <zope:class class=".test.Test">
>     <implements interface=".interfaces.IFooContainer" />
>     <implements interface=".interfaces.IBarContainer" />
> </zope:class>
> 
> Then I define AddMenuEntries for Foo and Bar implementations.
> 
> This does not work and as a result I only get Foo in the Add Menu. If I switch the two 
> implements zcml directives, I obviously get only Bar.
> 
> Is there a solution to configure a class to be both a FooContainer and a BarContainer with 
> constraintment ? (I would like to avoid dependencies between Foo, Bar and Test.)

IHMO you should use the containers()-statement on IFoo and IBar instead of
contains() on their containers. Even if the contains-constraints of
IFooContainer and IBarContainer would be merged somehow on the Test-class,
it wouldn't behave as you expect:

The contains()-statement can be read as "mustn't contain anything but...".
Mixing those two constraints depending on two different contained interfaces
would result in "Can't contain anything.".
This makes sense, if you have classes, relying on self.values() returning *nothing*
but objects implementing the given interface.

Regards,

Frank


More information about the Zope3-users mailing list