Package zope :: Package interface :: Module interfaces :: Class IInterface
[show private | hide private]
[frames | no frames]

Type IInterface

 Interface --+    
             |    
      IElement --+
                 |
 Interface --+   |
             |   |
ISpecification --+
                 |
                IInterface


Interface objects

Interface objects describe the behavior of an object by containing useful information about the object. This information includes:

o Prose documentation about the object. In Python terms, this
is called the "doc string" of the interface. In this element, you describe how the object works in prose language and any other useful information about the object.
o Descriptions of attributes. Attribute descriptions include
the name of the attribute and prose documentation describing the attributes usage.

o Descriptions of methods. Method descriptions can include:

o Prose "doc string" documentation about the method and its
usage.
o A description of the methods arguments; how many arguments
are expected, optional arguments and their default values, the position or arguments in the signature, whether the method accepts arbitrary arguments and whether the method accepts arbitrary keyword arguments.
o Optional tagged data. Interface objects (and their attributes and
methods) can have optional, application specific tagged data associated with them. Examples uses for this are examples, security assertions, pre/post conditions, and other possible information you may want to associate with an Interface or its attributes.

Not all of this information is mandatory. For example, you may only want the methods of your interface to have prose documentation and not describe the arguments of the method in exact detail. Interface objects are flexible and let you give or take any of these components.

Interfaces are created with the Python class statement using either Interface.Interface or another interface, as in:

 from zope.interface import Interface

 class IMyInterface(Interface):
   '''Interface documentation
   '''

   def meth(arg1, arg2):
       '''Documentation for meth
       '''

   # Note that there is no self argument

class IMySubInterface(IMyInterface):
   '''Interface documentation
   '''

   def meth2():
       '''Documentation for meth2
       '''

You use interfaces in two ways:

o You assert that your object implement the interfaces.

There are several ways that you can assert that an object implements an interface:

  1. Call zope.interface.implements in your class definition.

  2. Call zope.interfaces.directlyProvides on your object.

  3. Call 'zope.interface.classImplements' to assert that instances of a class implement an interface.

    For example:

    from zope.interface import classImplements
    
    classImplements(some_class, some_interface)
    

    This approach is useful when it is not an option to modify the class source. Note that this doesn't affect what the class itself implements, but only what its instances implement.

o You query interface meta-data. See the IInterface methods and
attributes for details.

Method Summary
    Inherited from InterfaceClass
  __contains__(self, name)
  __getitem__(self, name)
Return the attribute description for the given name.
  __iter__(self)
  direct(self, name)
  extends(self, interface, strict)
Does the specification extend the given interface?
  get(self, name, default)
Query for an attribute description
  getTaggedValue(self, tag)
Returns the value associated with 'tag'.
  getTaggedValueTags(self)
Returns a list of all tags.
  implementedBy(self, cls)
Do instances of the given class implement the interface?
  isOrExtends(self, interface)
Is the interface the same as or extend the given interface
  names(self, all)
Return the attribute names defined by the interface.
  namesAndDescriptions(self, all)
Return attribute names and descriptions defined by interface.
  providedBy(self, ob)
Is the interface implemented by an object
  queryTaggedValue(self, tag, default)
Returns the value associated with 'tag'.
  setTaggedValue(self, tag, value)
Associates 'value' with 'key'.
  validateInvariants(self, obj, errors)
validate object to defined invariants.
  weakref(self, callback)

Class Variable Summary
tuple __bases__ = (<InterfaceClass zope.interface.interfaces.I...
str __name__ = 'IInterface'
tuple __sro__ = (<InterfaceClass zope.interface.interfaces.IIn...

Class Variable Details

__bases__

Type:
tuple
Value:
(<InterfaceClass zope.interface.interfaces.ISpecification>,
 <InterfaceClass zope.interface.interfaces.IElement>)                  

__name__

Type:
str
Value:
'IInterface'                                                           

__sro__

Type:
tuple
Value:
(<InterfaceClass zope.interface.interfaces.IInterface>,
 <InterfaceClass zope.interface.interfaces.ISpecification>,
 <InterfaceClass zope.interface.interfaces.IElement>,
 <InterfaceClass zope.interface.Interface>)                            

Generated by Epydoc 2.1 on Fri Jun 24 12:01:26 2005 http://epydoc.sf.net