[Zope3-dev] schema initial documentation

Phillip J. Eby pje@telecommunity.com
Tue, 23 Apr 2002 10:16:34 -0500


At 05:27 PM 4/22/02 -0400, Jim Fulton wrote:
>"Phillip J. Eby" wrote:
> >
> > At 09:13 PM 4/20/02 +0200, Martijn Faassen wrote:
> >
> > >
> > >Interesting. I'm not entirely sure I see the overlap with schema, however.
> > >Do you mean to indicate a parallel between Field and Feature objects, in
> > >that they're both rather 'intelligent' part of an interface (as opposed to
> > >simple methods and attributes)?
> >
> > Sorry, I guess I wasn't expressing myself clearly.  What I meant was that
> > I'd like to be able to specify a feature in an interface, and have it imply
> > the existence of methods and/or fields in the interface.  Thus, if I added
> > a "limbs" feature to "IPerson", it would automatically add the "addLimb()"
> > and "removeLimb()" methods to the interface signature.
>
>So a feature is kinda like a macro.  Did you mean something like:
>
>   class IPerson(Interface):
>
>     arms = Limbs()
>     legs = Limbs()
>
>implies:
>
>   class IPerson(Interface):
>
>      def addArm(arm): ...
>      def removeArm(arm): ...
>
>      def addLeg(arm): ...
>      def removeLeg(arm): ...

That's the idea, yes.  The precise spelling of "Limbs()" might vary from 
the above; TW implementations of features are done with nested classes, e.g.:


class Limbs(SEF.Collection):  # SEF.Collection is a subclass of SEF.Feature
     ...

class Person(SEF.Element):

     class arms(Limb):
         ...

     class legs(Limb):
         ...


But this is an implementation spelling and obviously does not need to be 
identical for interfaces.


> > Of course, I can do this now using an explicit '__metaclass__' specifier to
> > build the interfaces, but it'd be nice to have the notion as a standard
> > part of documenting interface semantics.
>
>I'm afraid to ask what meta classes have to do with this.

They don't.  I was just pointing out that I can work around the 
non-existence of Features in the current Interface system like this:

def makeAnInterfaceFromFeatures(name,bases,dict):
     # create a new dictionary w/features expanded
     # and then return an Interface
     ...

class IPerson:

     __metaclass__ = makeAnInterfaceFromFeatures

     arms = Limbs()
     legs = Limbs()


Naturally, if the standard Interface metaclass introspected its contents 
and asked them to "expand themselves", then the above hack wouldn't be 
necessary.