Suppose you have a client-server architecture structured with a Client
class that asynchronously implements the Send()
and Receive()
functions.
You also have a base Message
class and several other classes inherited from that class, based on the type of communication. This is the scenario:
When a message is received, the
Receive()
function creates the right istance of the class which inherits fromMessage
class, which internally implements anHandle()
function.At the end of the
Handle()
function you need to send a message back using theSend()
function of theClient
.
To accomplish the point #2, which one of these two approaches represents the best-practice?
Decentralized approach:
call the Client.Send(ReplyMessage)
function directly from the Handle()
function in the Message
. This means that all the Message
classes can access and call the Send()
function in the Client
.
Centralized approach:
return the ReplyMessage
to the Client
, which will provide to call the Send()
function internally. In this way there is only one point where the messages are sent.