Ok, your headline is talking about a template for handling events. If you are talking about the real structure of events, then the Observer / Observable picture comes to mind. This will work when you want to fire an event of some type, and then the event handlers take away the event handling.
It looks like your problem is with the details of the implementation of the command template. Can you post code that shows where you are stuck?
Please note that the templates are not mutually exclusive; you can use the command template in the context of the Observable template.
EDIT - based on your code you should
1) make the statics CommandFactory .
2) pass the type to the getCommand method, which must also be static.
3) You do not need to reflect this, you can just do
if (type == "type1") return new Command1(); else if (type == "type2") return new Command2(); ...
I am not saying that you cannot use reflection, I am saying that it is too complicated what you are trying to do. In addition, they, as you do, bind a string representing the type of message with the details of the implementation of the class names of commands, which seems unnecessary.
source share