Class MessageDispatcher


  • public class MessageDispatcher
    extends Object
    Static resource for dispatching messages. Helps avoid visitor or double-dispatch intrusions into domain types.
    Author:
    John Collins
    • Constructor Detail

      • MessageDispatcher

        public MessageDispatcher()
    • Method Detail

      • dispatch

        public static Object dispatch​(Object target,
                                      String methodName,
                                      Object... args)
        Dispatches a call to methodName inside target based on the type of message. Allows polymorphic method dispatch without the use of visitor or double dispatch schemes, which produce nasty couplings with domain types.

        Note that this scheme finds only exact matches between types of arguments and declared types of formal parameters for declared or inherited methods. So it will not call a method with formal parameter types of (Transaction, List) if the actual arguments are (Transaction, ArrayList).