Python, without using Python
August 26th, 2008 by TrilobyteToday I faced a problem at work: I had to come up with a flexible, extendable architecture for a XML-RPC client service application. Both the client and server code had to be integrated into existing applications which makes the impact of introducing new message handlers painful if not designed properly.
While thinking about those requirements I quickly thought of a concept I saw in Python: Try to call find a callable method, otherwise do the default action. In Python you can use ‘getattr(…)’ to get a possible method of a class and with ‘callable(…)’ you can check if the method is actually a method.
You get something like this on your dispatcher object:
def Dispatch(self, methodName, arguments=None) method = getattr(self, methodName, None) if callable( method ): method( arguments )
I implemented this extensible architecture in exactly the same way. It was fairly easy to do, painless and it is extensible.
Learning multiple programming languages/concepts pay off!
