Serialization of the messages
Good day, programmers. I am a student and have a problem.
So, I have a client and a server, which have own messages (events), e.g., "logOut","RegisterUser" and so on.
The server passes different messages to the clients (and vice-versa). When the server (or client) receives a message, first it must read 2 byte.
I want to identify the object which would be created and, afterwards, fill fields in the created object. But I want to do it without "if" and "case".
I heard that I can identify the type of the object without "if" and "case" using a serialization of the messages. It doesn't exactly concern Java but object-oriented language.
I spent all day long searching any information about it but couldn’t find anything.
The problem is that those messages have different size. When I identify the type of the object which I need (reading first two bytes), I will create an instance of class. Then I will fill different fields of this class. That’s why I need this identification.
An idea flashed across my mind, and I decided to do Factory Message but some time later I refused this idea because different types of messages which are intended for the client and the server had different signature. That’s why I had to use two factories. I didn’t like this.
I gave this information just because I wanted to show that I had tried to find the solution of this question. I absolutely refused to use Factory and polymorphism.
How can I do it? Please help.
p.s. Sorry for my English, I know it a little.