I've lusted after this book for some weeks; I've used it by sitting at the Border's a number of times.
I am writing a basic client-server application in which the client sends different "types" of messages to the server ("Update record", "New record", "Delete record", etc.) I indicate the message type with a char variable;
char 'A' = SHOWALL;
in the header of the message. I send the message as a packet, with an int header giving the packet length, the char as noted giving the message type, then the payload, which could be null (as in a "BYE" message, or SHOWALL), or may contain data (in a DELETE or NEWRECORD message).
Anyway, I have a complex switch statement in the server which parses the message, finding the char COMMAND, and calling a set of methods appropriate to each type
One of my
java books suggests that a complex case-switch statement indicates type-checking, and an opportunity to use
polymorphism. How can I make my messages into different types (DeleteMessage, ShowAllMessage, UpdateMessage, etc.) either implementing or extending a Message interface (or abstract class), with one method, handleMessage()?
It seems that to construct the Message object, I have to go throught the same complex case-switch statement I described earlier, so I don't see the practical or aesthetic value of using polymorphism. On the other hand, I'd like to learn object oriented metodology, so I can feel like a professional some day.
Thanks in advance.
John