[Zope3-dev] Re: adapter registration question
Jean-Marc Orliaguet
jmo at ita.chalmers.se
Wed Nov 15 14:31:53 EST 2006
Philipp von Weitershausen wrote:
> Dieter Maurer wrote:
>> Philipp von Weitershausen wrote at 2006-11-15 15:08 +0100:
>>> ...
>>>> def myStrAdapter(something):
>>>> return str(something)
>>> It instantiates a 'str' object. The 'str' object is the adapter for
>>> 'something'.
>>
>> Huh? This would be a severe terminology abuse:
>
> I agree, it's bending the terminology a lot. It wasn't me who came up
> with the 'str' and 'int' example.
>
>> An adapter should adapt something to something else *BUT*
>> an "str" object does not adapt anything (it does not operate on
>> another object).
>
> Well, imagine
>
> >>> str(123)
> '123'
>
> Here '123' is the 'str' adapter of the integer 123. It's conceptually
> the same if you do
>
> >>> IZopeDublinCore(myobj)
>
> except that in the str(123) case, you call the class directly instead
> of using the Component Architecture's registry as a flexible dispatch.
>
But I guess Chris wanted to keep the registry lookup part, but not to
have to adapt the context.
in other words a utility that converts something to a string based on
the type to be converted.
once you have that utility / adapter you should be able to call it like:
converter = getAdapterFor(123, type=IToStringConverter)
strResult = converter.convert(123)
and reuse it:
strResult2 = converter.convert(456)
that saves a lot of CPU / memory.
PS: calling '123' an adapter is really bending concepts.
/JM
More information about the Zope3-dev
mailing list