[BlueBream] Chaining Adaptors
Mike Rhodes
mike at netsight.co.uk
Thu Jul 8 11:32:47 EDT 2010
On 08/07/2010 07:19, Michael Howitz wrote:
> To adapt A to C you have to define a specific adapter to do this adaption. This adapter could look like this:
>
> @zope.component.adapter(InterfaceA)
> @zope.interface.implementer(InterfaceC)
> def adaptAC(a):
> return InterfaceC(InterfaceB(a))
>
> (You still have to register this adapter but the decorators make it easier to register it via ZCML.)
>
> The reason why this does not work out of the box is that zope.component had to guess the chain. It had to do conflict resolution when there is more than one chain. Think of chains with more than two elements, this can lead to a huge matrix of possible chains where each has to be tested if it works.
>
> And at least: explicit is better than implicit.
Thanks for the clarification that this isn't intended to work. I must've
read an unreliable rumour at some point :)
I can see that in the general case this has a change to spiral up into a
large matrix, but for a list of a few tens to hundreds of adapters I'm
not sure this would be too bad, especially the network formed by
adapters isn't fully connected. Adding a cache to this would speed up
commonly requested adapters to reasonable levels.
Storing a directed graph in memory and running a good path-finding
algorithm over it could be a starting point if this functionality was
desired. I'm not sure how the PyProtocols mentioned by Justin does this,
and what its efficiency characteristics are.
However, I can see that multi-adaptors complicate this picture
substantially. And I imagine the topic has come up and been dismissed
before, can anyone point me toward any previous discussions?
It sounds like a fun project, but I don't want to start down a rabbit
hole if it's already been deemed unwise!
Mike.
--
Netsight / www.netsight.co.uk
0117 909 0901 (ext. 23)
More information about the bluebream
mailing list