I have the following class structure: a base class 'Message' which contains some common members (/fields), 'Imessage' interface that has some methods that all messages should implement, a lot of different message classes that extends (inherits) the base 'Message' class and have a lot of fields, an enum for each message type and a factory class which given an enum creates an instance of the proper message class.
The issue is that I'm not sure where/how to implement the setting of values for each of the message classes. It can't be in it's constructor because in the factory method i need to build generic instances. Should i implement a 'Create' method for each of the messages that will set all of it's members?
public static Message buildMessage(MessageType messageType)
{
Message message = null;
switch (messageType) //TODO: add all messages!
{
case CONNECT:
message = new ConnectMessage();
break;
case CONNECT_RESPONSE:
message = new ConnectResponseMessage();
break;
case DISCONNECT:
message = new DisconnectMessage();
break;
case FLOWSTART:
message = new FlowStartMessage();
break;
default: return null;
}
return message;
}