wiki:CodeGuide

Code Guide

Messages and message handling

All modules in our event-oriented environment exchange messages. All messages are derived (directly or not) from 'appcore.Message' class. In particular, all messages that are at any point sent over the network are derived from 'communication.messages.CommMessage' class.

To handle incoming messages, modules implement a variation of the Visitor pattern (http://en.wikipedia.org/wiki/Visitor_pattern), which might be called "Visitor Pattern with Defaults" (http://stackoverflow.com/questions/985960/alternative-to-the-visitor-pattern). In our case, there is no java interface but only an abstract class 'appcore.MessageVisitor', which should be a parent of all visitors implemented throughout the system.

(Bonus: interesting article about double dispatch: http://www.drdobbs.com/double-dispatch-with-an-inverted-visitor/184403497)

Adding new message

If you wish to create a new message class you need to do the following steps:

  • create a new class, e.g. 'MyMessage', which is a (possibly indirect) descendant of 'appcore.Message',
  • add new 'visit' method with a single argument of type 'MyMessage' to 'appcore.MessageVisitor',
  • implement 'accept' method in your 'MyMessage' class with body matching the one from 'appcore.Message' (IMPORTANT: this needs to be done in EVERY message class, even if the method is already implemented in base class).
Last modified 5 years ago Last modified on 10/14/13 20:09:15