I have a hard time understanding when the Single Responsibility Principle is correctly used. Consider the following code:
// --------------------------------------------------------------------------------------------------
void CTCPClient::Try_Send_Data(const char *Outgoing_Message)
// --------------------------------------------------------------------------------------------------
{
Reset_Return_Value();
Copy_Data_Into_Buffer(Outgoing_Message);
try
{
if((strcmp(Outgoing_Message, "") != 0))
{
Send_Data();
Keep_Alive_Counter = 0; // reset as a button has been pressed
}
if(Return_Value < 0)
{
throw SEND_DATA_TCP_ERROR;
}
}
catch(EError_ID)
{
Error_Message = strerror(errno);
LOG_WARNING(__SOURCE__ << Error_Message);
}
}
If I would read this method for the first time, I would, as the name sugest, expect a try and catch statement. But before that I´m calling two additional methods (Reset_Return_Value(), Copy_Data_Into_Buffer()). Is the SRP already violated here?
Further in the method I'm setting "Keep_Alive_Counter = 0;". In my opinion, at least at this point the SRP has been violated in addition to the fact, that if I were to be someone who didn't write the code, would simply not expect this line to be there. The problem I have here is: If I do this in an explicit method, it will be a one line method, something I encounter more often, as I try to consinder the SRP. These methods still look weird to me and I haven't found an answer to when they are considered good pratice. Always? In some cases? Never?
This is my own code so feel free to criticize, as long as it is constructive.
EDIT: Keep_Alive_Counter and Return_Value are class attributes, which are changed/used by other methods.