[Zope3-dev] Re: Circular references between interfaces

Peter Mayne PeterMayne at ap.spherion.com
Sun Oct 10 20:31:18 EDT 2004


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.

PJDM
-- 
Peter Mayne
Spherion Technology Solutions
Canberra, ACT, Australia
"You're given the form, but you have to write the sonnet yourself.
What you say is completely up to you." - Mrs. Whatsit



More information about the Zope3-dev mailing list