[Zope3-dev] RFC: Change in automatic detection of
providedinterfaces
Garrett Smith
garrett at mojave-corp.com
Wed Apr 6 09:42:03 EDT 2005
Jim Fulton wrote:
> A recent simplification was made to adapter and utility registration.
> When registering adapters, the provided interface can be ommitted
> if the registered factory implements a single interface. Similarly,
> when registering utilities, the provided interface can be ommitted
> if the registered component provides a single interface.
>
> The intent is that if you have something like:
>
> class MyClass:
> implements(IFoo)
>
> ...
>
> you do not have to repeat IFoo in the registration.
>
> The current scheme runs into problems if you use inheritence:
>
> class MyClass(SomeBase):
> implements(IFoo)
>
> Then declarations in the base class cause the subclass
> to implement multiple interfaces.
>
> I'd like to make the following change to algorithm for determing
> the provided interface if nothing is specified in the rgistration:
>
> For adapters, if the registered factory directly implements
> a single interface, then that interface will be used. Inherited
> interfaces will not be considered. If the factory directly
> implements no interfaces or more than one interface, then a
> provided interface must be provided in the registration.
>
> For utilities, if the registered component directly provides no
> interfaces and its class directly implements
> a single interface, then that interface will be used. Inherited
> interfaces will not be considered. If the component directly
> provides any interfaces or if its class directly implements
> no interfaces or more than one interface, then a provided interface
> must be provided in the registration.
>
> So, for example, if we have:
>
> class B:
> implements(IB)
>
> class S(B)
> implements(IS)
>
> we can register S or an instance of S without specifying a provided
> interface. The interface IS will be used.
>
> However, with:
>
> class S2(B):
> pass
>
> You would have to sp[ecify a provided interface if you registered S2
> or an instance of S2.
>
> Thoughts?
Seems straight forward enough. Personally, I view the implements clause
in these cases as a substitute for the provides in ZCML, so I always
list a single interface anyway in such cases.
-- Garrett
More information about the Zope3-dev
mailing list