[Twisted-Python] adapt from more than one interface
jml at mumak.net
Sat Apr 11 20:22:08 EDT 2009
On Sun, Apr 12, 2009 at 10:31 AM, <glyph at divmod.com> wrote:
> On 11 Apr, 08:41 pm, esteve at sindominio.net wrote:
>> factory = IFooFactory(myService)
>> factory.bar = "some value"
>> it works, but I'd rather use this:
>> factory = IFooFactory(myService, configurationObject)
> This is a long and terrible road you're about to start down. It's hard for
> me to explain exactly why it's so painful, but trust me, it is.
> What you're doing now, passing out-of-band arguments to the IFooFactory
> adapter, whose concrete type you are *not supposed to know* at that point in
> the control flow, is bad. But trying to force adaptation to become
> full-fledged multimethods is worse. If you want multimethods, I believe
> PEAK provides a package that implements them.
Also, Zope has getMultiAdapter(). The canonical example is adapting a
model object and a request object to a view object.
I don't think it's as bad as glyph says. I probably wouldn't use it in
the case you describe -- calling methods on objects is almost always
More information about the Twisted-Python