Search code examples
architecturemessage

message oriented communication in stand alone application - does it make a sense?


strange question regarding application architecture, but maybe you can help me with it :-).

Is there any sense of using messages for inside communication in stand alone application ?

To be clear, I'm not talking about MOM, but a single application with MVC or PAC architecture inside (or any architecture, composed from multiple cooperating modules). Also the messaging system is not defined here, we can assume that it is something what allows to create and send an objects from one to another application module instead of a simple method call (so basically send(Message) instead of ilights->lightOn(bool) function call).

So assume that such an application has multiple modules, some of them depends on the others (hierarchical tree), some others are on same level of hierarchical tree etc.

And now the question, does it have a sense to use any kind of messaging system, instead of passing interfaces and then use them just to call the required methods ?

From one point of view using messages can help us to decouple the modules, but which modules ? Just the modules on the top of the modules tree or the messages should go deeper (how deep) ?

There is also second point of view, the messaging system increases the amount of boilerplate code (we need to define messages, create handlers, dispatchers etc, instead of simple method call) so there is some additional work.

Is there any golden mean or just using messages inside stand alone application is totally pointless ?


Solution

  • There is no definite answer here. Every such question has to be analyzed from the point of view of requirements.

    There are obvious things you mentioned (decoupling of dependencies for messages, quicker development time for direct method calls) which may be important (or not).

    Without analyzing the requirements the answer will be opinion based. E.g. I can think of multiple reasons for an application internal messaging system:

    • adding and removing messages (assuming the same base class) is robust: just add a handler to the dispatcher or ignore the new message
    • adding events based on messages is easy
    • adding multi threading later becomes easier (dispatcher can do it in a central place
    • you can log messages easier than function calls