[Zope3-dev] Interfaces as factories

Martijn Faassen faassen at infrae.com
Fri Jul 2 04:26:58 EDT 2004


Nicholas Seckar wrote:

> To avoid these issues, code should not instantiate
> objects from a class or factory, but from an
> interface. Interfaces would then become not only
> structure specifiers, but also factories.

How does this relate to the use of interfaces as adapter factories, as 
is possible right now, i.e.:

myadapter = IFoo(content)

Would seem that if your factory needs arguments, there'd be a conflict 
with adapter factories, unless you define construction of content 
objects as a form of adaptation somehow. No idea whether that is a sane 
idea, I'll leave it to Jim and Steve who like to consider everything as 
a special kind of adapter. :)

[snip]
> The proposed solution to this is to create a
> centralized interface repository to avoid 'Module not
> found' errors. Interface lookup would be performed via
> an object with an overloaded __getattr__, which would
> be placed in the zope package with a path such as
> 'zope.interfaces'. Packages could then register their
> interfaces through ZCML, and specify a fitting
> pseudo-module path, such as
> 
> 'zope.interfaces.components.textual.IRestructuredTextSource'
> Instead of these paths representing package structure,
> which is not always static, these paths would
> represent functionality, which, for most interfaces,
> should be static.

This is an interesting concept. We had a central registry of interfaces 
before, but we actually *placed* the interfaces in a seperate package, 
and this was hard to maintain. Being able to register them into a 
virtual tree might be more maintainable, though it also puts a 
dependency on this system in Python code. If I install a Zope 3 package 
now, I can use it if it doesn't have other dependencies. If instead it 
imports interfaces from the virtual package, there are two problems:

   * how do I find out which package provides such an interface? I.e. 
what is the dependency?

   * I'm unable to actually run packages without the interface 
registration process taking place.

Regards,

Martijn


More information about the Zope3-dev mailing list