CommunicationBetweenModules
ThoughtStorms Wiki
Context : OnModularity
Thinking of modules not as a specific to any language, but aggregate lumps of code.
I can think of six ways two modules can communicate :
- 1) through explicit function calling / message passing via a well defined / explicit interface
- 2) through shared access to global variables (or variables in an enclosing scope)
- 3) through a "signals" type system (which behind the scenes, traps some event (eg. database update) and calls some dependent code)
- 4) "stigmergically" : one module updates a database, file or other shared resource, and when the other module comes to read it, it notes and reacts to the change (StigmergicSystems / SubsumptionArchitecture)
- 5) "control coupling" ... which does involve some kind of function call / message being passed but is distinguished in that the call simply passes a complex data-structure which the receiving module makes some kind of interpretation of
- 6) asynchronous message passing - a variation of message passing where one module passes a message to the other, which, at an unspecified time later may pass a message back (or call a callback)
Now, my question is, when are these appropriate or not?
Intuitively, my assumption is that (1) is always the way to go unless you specifically need one of the others. (This is surely the main lesson that's been realized over the last 40 years or so)
(2) is usually a bad idea. Except in maybe very special circumstances, where the modules are very small and the scope of the shared variable easily understood (eg. two short functions defined within the same closure)
... to be continued
Backlinks (1 items)