[Zope3-dev] N-Tuple Adapters

Phillip J. Eby pje@telecommunity.com
Tue, 03 Jun 2003 09:23:17 -0400


At 11:44 PM 6/2/03 -0400, Shane Hathaway wrote:
>On Mon, 2 Jun 2003, Phillip J. Eby wrote:
>
> > package has this capability; see
> > http://peak.telecommunity.com/protocol_ref/proto-implication.html for the
> > section of the reference that deals with "adapter paths" and relative
> > precedence of different routes for an adaptation.  One of the (relatively)
> > original contributions of PyProtocols is that it considers "implementing"
> > an interface to be a special case of adaptation (the NO_ADAPTER_NEEDED
> > adapter!), rather than the other way around.  This makes transitive
> > adaptation and making new "subset" protocols (think reverse interface
> > inheritance) easy and natural operations, not to mention fast.
>
>Whew, you like to turn everything on its head.  It sounds neat though. ;-)
>
>I followed up to the last word.  How does this make it fast?

Because the adapter composition (and recursion) is done at declaration 
time, rather than at retrieval time.  Whenever you register an adapter, the 
registration is forwarded to all implied protocols immediately, so long as 
the registration resulted in a shortened adapter path.  As soon as a 
registration fails to shorten an adapter path, recursion stops.  At that 
point, the network of adapter paths is up-to-date.  Each protocol then 
knows exactly how to adapt anything that comes its way.  Average lookup 
time is proportional to the MRO length of the incoming objects' classes: 
one dictionary lookup occurs for each class in the MRO, until an adapter 
path is found.  The adapter path is then simply invoked.