[Zope-dev] improving the utility and adapter lookup APIs
dev at projekt01.ch
Wed Nov 25 21:01:13 EST 2009
> Betreff: Re: [Zope-dev] improving the utility and adapter lookup APIs
> On Nov 25, 2009, at 11:17 AM, Thomas Lotze wrote:
> > Martijn Faassen wrote:
> >> Adapter:
> >> IFoo(x)
> > [...]
> >> Multiadapter:
> >> IFoo.multi(x, y)
> > [...]
> >> Utility:
> >> IFoo.utility()
> >> [or possibly IFoo() instead?]
> > What about a simple and consistent API for all components including
> > utilities, adapters and multiadapters:
> > IFoo()
> > IFoo(x)
> > IFoo(x, y)
> > I seem to remember there had been some discussion at some
> point about
> > dropping or at least loosening the distinction between
> utilities and
> > adapters anyway, so this would be the opportunity to do so
> at the API
> > level.
> That was discussed and rejected near the very beginning of
> the Z3 effort, in my memory. They are too different. Our
> use of adapters generally involves looking something up and
> automatically calling it. Our use of utilities generally
> involves simply looking something up and returning it.
Of corse do adapter adapt something.
But why do we excpect that we will get an adapter if we enhance
the interface implementation and do some dance with e.g. IFoo(???).
Form the interface point of view there should only be a
contract that the returned object provides that interface.
Adapters and utilities are different, that's no question.
But if an interfaces get called without an argument, it could
return an object providing this interface. Based on the missing
value (not None, just missing) the object doesn't get
adapted/called and could return an utility.
If we skip this option, then IFoo() will raise a ComponentLookupError
or tell us that the signature at least needs one or more argument.
The following makes sense to me:
getUtility(IFoo) -> IFoo()
getUtility(IFoo, name='foo') -> IFoo(name='foo')
getAdapter(obj, IFoo) -> IFoo(obj)
getMultiAdapter((foo, bar), IFoo) -> IFoo(foo, bar)
> Zope-Dev maillist - Zope-Dev at zope.org
> ** No cross posts or HTML encoding! ** (Related lists -
> https://mail.zope.org/mailman/listinfo/zope )
More information about the Zope-Dev