Programming with Adaptors

Share the article!

20030630060058

“Programming with Adaptors” a new term I’m making up.  It’s really nothing new, but recently it’s being taken to new levels. 

Exhibit A, Spin:

We will present our project named Spin which offers a – to our knowledge – revolutionary new approach. It offers transparent thread handling with minimal impact on your application code.

Exhibit B, PyProtocols

Do you hate having to write lots of if-then logic to test what type something is?  Wouldn’t it be nice if you could just declare “I want this object to have this behavior” and magically convert whatever value you have, to the type you need?  PyProtocols lets you do just that, cleanly, quickly, and robustly — even with built-in types or other people’s classes.

Spin is somewhat similar to the interceptor based approached to AOP, however it adds an adaptor to respond to events that makes it worthy of more indepth study.

PyProtocols, well this is something you really have to dig in deep. Here are some of its features:

  • Specify what behavior a component requires or provides

  • Specify how to adapt the interface provided by one component to that required by another

  • Specify how to adapt objects of a particular type or class (even built-in types) to a particular required interface

  • Automatically adapt a supplied object to a required interface, and

  • Do all of the above, even when the components or frameworks involved were not written to take advantage of this package, and even if the frameworks have different mechanisms for defining interfaces.

Now if you reflect a bit, you realize that a lot of menial work in programming covers the transformation of one type into another.  It’s just embarassing the amount of time spent doing this kind of activity. It makes so obvious the limits of Object Oriented resusability. 

The reasons are also equally obvious.  If you continue to develop objects with different kinds of methods.  Then you’ll continue to need to write an adaptor that transforms one object to another, at worse the amount of progamming is like O(n^2).  So we can either not define any new kinds of objects (or more precisely interfaces) or we can make programming adaptors much easier.  

REST for example takes the approach of not defining any new interfaces.  Rickard Oberg’s AOP framework tends to work of a minimized set of interfaces and composing adaptors using aspects.   The PyProtocol takes an different approach, however its sythesis with an AOP approach may lead to pretty astonishing levels of reusability.


Share the article!

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>