I'm trying to figure out how best to deal with the following scenario. I have a server that receives messages, processes them, and then sends responses back to a client. I want to have the processing
step return detailed information about the results of processing performed and an object in some cases.
I have code like the following:
public void HandleMessage(Connection conn, Packet packet) {
var somedata = packet.Read();
var result = Process(somedata);
if (result == typeof(Message))
SendA(result);
if (result == typeof(MyObject))
SendB(result, extraInfo);
}
public [what goes here] Process(object data) {
if (validated)
return data;
else
return Message.Failed;
}
What I want to do is create a separation of responsibilities.
- Receiver : parses data into meaningful objects
- Processor : acts upon parsed data and returns a status code or object.
- Sender : interprets returned data from a processor(s), constructs a packet, and sends this to the client.
What kind of design should I try to implement to achieve something like this?
Aucun commentaire:
Enregistrer un commentaire