I am creating a board game with Project RedDwarf framework (old project DarkStar).
My question is this:
I need to have commands sent back and forth from the server to the client and reverse, and I need a solid programming architecture to incorporate on the command messaging service.
I thought of having a Command interface, and each subcommand would be an implementation of it (which holds the command String).
For instance lets say we need to check if a user is online. We have an interface called Command, then an interface called Check which extends Command, and finally we have the implementation called OnlineCheck.
OnlineCheck could have a method called getCommand and would return the commands String.
Ok till now.. BUT what I really wanna do is, include the possible replies on the same implementation class, so that I can check what the client replied to me, based on one of the pre defined replies.
How should I go about doing this?
Firstly, appreciate the use of command pattern.
Command interface should have an entry point like
execute()orrun()that would implement what OnlineCheck should do. So there needn’t be anygetCommand()that in turn returns the command string which again needs to be interpreted.Once you go down this path, the command instance (an instance of OnlineCheck in this case) could hold the response and can be sent back to the client. The client in turn would give this response back to the code block that generated it as it would be the best one to know what type of responses to expect for this command and can interpret them appropriately.
My two cents!