I have many classes , say,
class A
{
/*member variables*/
};
class B .. Class Z
I am copying objects of these classes into a buffer (char*). Now I have a reader object that continuously polls this buffer and deserializes the bytes into objects and prints them. My question is how should the deserialzer class be designed.
The approach I have is to embed the type of the object as a header and then send it through the buffer. Upon reading the buffer, I know the type and then I can deserialize the appropriate object. The problem with the deserializing part is now it should be aware of all the message types and call the appropriate function based on the type. I am planning to have this deserialization as a separate entity that is not aware of the message types or the code to deserialze it should not be a part of it.
I am looking for solutions like interfaces, polymorphism etc. to tackle this problem. Is there a design pattern for this kind of a problem ?
Aucun commentaire:
Enregistrer un commentaire