Skip to main content

One bird, two stones

·2 mins

Glyph thinks that interfaces are great, and he is right (although I haven’t read the full post, I certainly agree with the title).

One of the natural things you can do with interfaces is this: make a new class Bar that delegates all of the properties of IFoo to an instance of class Foo. This is the Decorator pattern (not to be confused with Python’s decorator syntax), and is also the Bird in this parable.

We use interfaces a lot in Launchpad, and we need to Decorate classes quite a bit. So, we wrote something to make it easy and open sourced it. It’s called lazr.delegates. This is Stone One, if you like.

Stone Two was actually cast first, and is called twisted.python.components.proxyForInterface. It’s distributed as a part of Twisted, and solves exactly the same problem. For those interested, here’s the Twisted implementation (scroll to line 320ish) and here’s the lazr implementation.

Both implementations are fairly simple, and yet it is perhaps a shame that there are two of them. If anyone is at fault, it’s me, since I knew about proxyForInterface and watched lazr.delegate arrive in the Launchpad tree without even thinking that the two might actually be the same thing.

But I wonder, is there a process bug here? Is there something Launchpad, Twisted, Zope or Guido could have done to avoid this?