[Grok-dev] [Zope3-Users] Interface Use Cases

Thierry Florac thierry.florac at onf.fr
Wed Jan 28 08:20:55 EST 2009


Le mercredi 28 janvier 2009 à 10:39 -0200, Tim Cook a écrit :
> All,
> 
> I have many places where I have used this in a schema.
> 
> class IAbc
> attr1 = Object(schema=IAbc)
> 
> class Abc(object):
> """does some stuff but is usually an abstract class"""
> implements (IAbc)
> 
> Where IAbc is actually meant to represent that any one of (let's say)
> three different sub-classes of Abc would be acceptable for that
> attribute.
> 
> I think my approach is completely wrong but I do not understand all the
> different cases to use implements, Provides, classImplements, etc.
> 
> 
> so if I had:
> 
> class Def(Abc):
> implements(IDef)
> 
> class Gbn(Abc):
> implements(IGbn)
> 
> class Xds(Abc):
> implements(IXds)
> 
> 
> What is the correct function to use and where so that when attr1 is
> assigned a value it will be happy with an instance of Def, Gbn or Xds?
> 
> But nothing else?


Hi,

If I correctly understand your question :

        from zope.schema.fieldproperty import FieldProperty
        
        class Abc(object):
            implements(IAbc)
            attr1 = FieldProperty(IAbc['attr1'])
        
Like that, each time attr1 will receive a new value, this value will be
checked to ensure it provides IAbc, otherwise a SchemaNotProvided
exception will be raised.

Hope this will help you,

  Thierry Florac
-- 
  Chef de projet intranet/internet
  Office National des Forêts - Département Informatique
  2, Avenue de Saint-Mandé
  75570 PARIS Cedex 12
  Mél : thierry.florac at onf.fr
  Tél. : +33 01.40.19.59.64
  Fax. : +33 01.40.19.59.85



More information about the Grok-dev mailing list