[Grok-dev] Simple adapter question

Martin Aspeli optilude+lists at gmail.com
Thu Mar 5 23:03:52 EST 2009

Jan Ulrich Hasecke wrote:

> So why the class Home is defined at all?

Home is the actual adapter (or, more precisely, the adapter *factory*: 
the thing that Zope calls to get back an instance of the adapter 
(calling a class object gives you an instance object)). It needs to be 
defined somewhere.

I think the reason why this is confusing is that the adapter is the 
defined in the same code listing as the user of the adapter. The point 
of using an adapter is normally that you have multiple possible contexts 
coming from different sources, spread over your code base. You adapt 
those to an interface you know how to deal with, in order to make your 
code more re-usable.

Also, the example isn't terribly realistic, and even then, 
multi-adapters are most commonly used as an implementation detail behind 
browser views (which multi-adapter a context object and the request). 
I've used them in code I've written, but usually only in "framework" 
type code.

If you have my book, you may find parts of chapter 9 useful reading on 
this topic as well.


Author of `Professional Plone Development`, a book for developers who
want to work with Plone. See http://martinaspeli.net/plone-book

More information about the Grok-dev mailing list