[Zope3-dev] Re: Circular references between interfaces

Philipp von Weitershausen philipp at weitershausen.de
Mon Oct 11 17:21:51 EDT 2004


Peter Mayne wrote:
> I ended up using an intermediate interface, and then subclassing that 
> for the real interface:
> 
> class IDummyActor(Interface):
>     pass
> 
> class IActorRef(Interface):
>     '''A reference to an IActor from an IMovie.'''
> 
>     actor = Object(
>         title = u'Actor',
>         description = u'The actor.',
>         required = True,
>         default = None,
>         schema = IDummyActor)
> 
> class IMovie(Interface):
>     '''Movie definition.'''
> 
>     cast = List(
>         title = u'Cast',
>         description = u'Cast list.',
>         value_type = Object(IActorRef, title = u'Actor reference'),
>         default = [],
>         required = False)
> 
> class IActor(IDummyActor):
>     '''Actor definition.'''
> 
>     movies = List(
>         title = u'Movies',
>         description = u'Movies this actor has been in.',
>         value_type = Object(IMovie, title = u'Movie reference'),
>         default = [],
>         required = False)
> 
> That worked fine until (for other reasons) I changed the schema again, 
> so I ended up not needing the circular definition.
> 
> Jim Fulton wrote:
>  > Perhaps we should add an API for adding an attribute definition to
>  > at interface.
> 
> I'm not sure I like adding an attribute definition to the interface, 
> because the interface definiton ends up being spread around the 
> interfaces file in more than one place, which makes it harder to read. 
> Adding an API might encourage people to do it. :-)
> 
> Stephan Richter wrote:
> 
>  > IActor.getDescriptionFor('movies').value_type.schema = IMovie
> 
> I never would have looked at getDescriptionFor() as a method for this. I 
> had this confused with the description u'Movies this actor has been in.' 
> in the movies field, rather than the movies field itself. Perhaps 
> getFieldFor() would have been a better name.

Actually, `getDescriptionFor` and `queryDescriptionFor` are not 
documented in IInterface so, thank God!, they're not part of the 
official interface interface (and thus should go away IMHO!).

Use IActor.get('movies') or simply IActor['movies'] instead.

Philipp



More information about the Zope3-dev mailing list