Wednesday, July 26, 2006

Proposed system for subcomponent flexibility

Many Kamaelia components need to create their own subcomponents at run-time, e.g. my HTTP client spawns a TCPClient to connect to the server. However, this can cancel out much of the flexibility that a component-based architecture provides. As an alternative to hard-coding the class of each subcomponent, I propose that every subcomponent should be created from by a function provided as an argument at that components creation.

For example, in SingleShotHTTPClient:
def __init__(self, starturl, postbody = "", connectionclass = TCPClient):
self.connectionclass = connectionclass
And whenever a TCPClient was created in the old code, connectionclass is now called with the same parameters. The possibilities added by this are great:
  • for debugging, TCPClient could be replaced with a local console masquerading as a TCP connection.
  • TCPClient could also be replaced by a SOCKSTCPClient allowing it to go via a SOCKS proxy.
  • for logging purposes, connectionclass could be a wrapper function (rather than a class) that wrote the host addresses accessed to a file before spawning and returning a TCPClient
  • etc.
Most importantly, all these things could be done without having to change the code of I propose that this practice should become standard.



Post a Comment

<< Home