Christof said:
And what about
void f(int data)
void f(int data, bool withLogging)
void f(int data, string loggingSource)
There are many similar examples in the CRL
Christof
Nothing wrong with doing that!
The pattern I use for this type of situation is like this:
public void f(int data)
: this(data, false, null) {}
public void f(int data, bool withLogging)
: this(data, withLogging, null) {}
public void f(int data, string loggingSource)
: this(data, true, loggingSource) {}
public void f(int data, bool withLogging, string loggingSource) {}
These are all basically convenience overloads for the caller.
The first one means "call f and don't do any logging at all."
The second one means "call f and log or don't depending on the
withLogging parameter's value; if withLogging is true log to the default
log source."
The third is "call f and log or don't log depending on the withLogging
parameter's value, and further if withLogging is true then log to the
source specified in loggingSource (unless the caller explicitly
specified null in which case log to the default log source)."
And sometimes the 4th one is private if I don't want to expose that
variant of the constructor. I also use this same pattern with method
overloads quite frequently as well.
There is a bit of an art to coming up with good, useful overloads and
not just overloading for the sake of it.