Communication between modules
- by David Elentok
I have an application that consists from the following three modules:
Search (to search for objects)
List (to display the search results)
Painter (to allow me to edit objects) - this module isn't always loaded
(Each object is a figure that I can edit in the painter).
When I open an object in the painter it's added to the objects that are already in the painter and I can move it and alter it.
I'm using an object similar to the EventAggregator to communicate between the modules. For example, to show the search results I publish a "ShowList" event that is caught by the List module (I'm not sure this is the best way to do this, if anyone has better idea please comment...).
One of the features of the search module requires it to get the selected object in the painter (if the painter is available), and I'm not sure what would be the best way to do that...
I thought of these solutions:
Whenever the selected object in the painter changes it will publish a "PainterSelectedObjectChanged" event which will be caught by the search module and stored for later use.
When the selected object is needed by the search module it will publish a "RequestingPainterSelectedObject" event which will be caught by the painter module. The painter module will then set the "SelectedObject" property in the EventArgs object, and when the publish is complete and we're back in the search module we will have the painter's selected object in the EventArgs object.
What do you think? what is the right way to do this?