[Interface-dev] zope.interface calling an interface with no arguments

Fred Drake fdrake at gmail.com
Wed Aug 31 22:32:57 EDT 2005


On 8/31/05, Daniel Krech <eikeon at eikeon.com> wrote:
> We're in the process of adding Interfaces to rdflib using Zope
> Interfaces and also replacing rdflib's home brewed plugin system. So

Very cool!

> far things are going well, but we've run across something we'd like
> to be able to do, namely, create an instance by calling the interface
> with no arguments. For example:

This sounds like you're looking for more than just the interface
definitions, but for something like the component architecture as well
(zope.component).

The component architecture adds support for registries of objects that
provide interfaces that can then be used as utilities.  The model that
we'd follow would be to define an interface for a *factory* that
creates objects of particular types.  A factory typically has one
method (__call__), that takes whatever arguments are needed.  If there
are different sets of arguments that may be passed, several methods
can be defined for the factory interface, or different factory
interfaces can be defined.  Code that wants to create objects of a
certain interface looks up the corresponding factory interface (which
it can do just once) and then use the factory to produce instances. 
Something like:

    factory = zope.component.getUtility(IThingFactory)
    thing_one = factory()
    thing_two = factory()

This has been working well so far in Zope 3; I think we're all really
happy with it.  It might be worthwhile looking at zope.component from
the Zope 3.1.0c2 release or from a Subversion checkout.


  -Fred

-- 
Fred L. Drake, Jr.    <fdrake at gmail.com>
Zope Corporation


More information about the Interface-dev mailing list