[Interface-dev] Re: Doing multi-adaptation through interface call
(again)
Philipp von Weitershausen
philipp at weitershausen.de
Sun Aug 15 14:08:21 EDT 2004
Jim Fulton wrote:
> C. Add additional methods to interfaces. I wanted to avoid cluttering
> the interface API with to much component support, however:
>
> - Adaptation is a pretty important feature of interfaces, and
>
> - Zope's component architecture is coalescing to the point where it
> consists solely of adapters and utilities, where, clearly, adapters
> are the most important.
>
> - The adapter registry is provided by the interface package, so, perhaps
> it makes sense to surface access to registries in the interface API.
>
> If we did this, I'd probably add the following interface methods:
>
> def multi_adapt(*objects, **options):
> """Adapt multiple objects
>
> Options:
>
> - default: The value to return if no adapter can be found. This
> defaults to None
>
> - name: Look up a named adapter with the given name.
> """
>
> def subscribers(*objects):
> """Return the subscribers for the given objects
>
I like this option best. Single adaption and multiple adaption are two
different things with very different semantics. Same goes for
subscription adapters. It therefore makes much sense to have different
methods and different adapter hooks for all three of them.
Regular adaption:
>>> IFoo(a)
>>> IFoo(a, default)
Multiple adaption:
>>> IBrowserPublisher.multi_adapt(object, request, name=u'index.html')
>>> IInputWidget.multi_adapt(field, request, obj, default=None)
Subscribers:
>>> for subscriber in IFoo.subscribers(a, b):
... if some condition:
... break
> This is slippery slope. I can also think of a number of other methods
> to handle more obscure cases that are needed in Zope, but not often.
Well, obscure cases should not be our guide here :)
Philipp
More information about the Interface-dev
mailing list