If I have a method that does something and additionally logs information, should I create a new method if I don't want to log or use a flag?
public void MethodA(string myMessage, bool logIt)
{
if(logIt)
{
//do stuff with logging
}
{
//don't need to log
}
}
...vs...
public void MethodA(string myMessage)
{
//do stuff with logging
}
public void MethodANoLogging(string myMessage)
{
//don't need to log
}
My scenario is simple and I'm mainly interested in the flag parameter, which could be an enum creating many if...else if...else if scenarios within the same method. Versus just creating a new method with a different name. I'm in favor of the second solution (new method) since it allows methods to have one responsibility. Fundamentally, that is a simpler solution.
What would be the reason to use the flag version?