Here's a coded example of what I mean: This is the first example where the methods are chained from most parameters to least parameters. This assumes that the methods with additional parameters are doing more work.
public void DoSomething(int a, int b, int c)
{
// Do stuff with a, b and c
}
public void DoSomething(int a, int b, int c, int d)
{
// Do some preliminary stuff with d - optional
DoSomething(a, b, c);
// Do additional stuff with d - optional.
// Note: You must do something with d
}
public void DoSomething(int a, int b, int c, int d, int e)
{
// Do some preliminary stuff with e - optional
DoSomething(a, b, c, d);
// Do additional stuff with e - optional
// Note: You must do something with e
}
NOTE: It is sometimes the case where the version with the most parameters is actually going to do all the work, and the other overloads just provide default values into the method that does the work. Think MessageBox.Show (A lot of its overloads just provide default values for the buttons, icon and so on.) However, if the work is incrementally increased with the number of parameters then the code I showed above is likely to be better.
Upcoming events: * Edinburgh: Web Security Conference Day for Windows Developers (12th April) * Glasgow: Introduction to AJAX (2nd May), SQL Server, Mock Objects Never write for other people. Write for yourself, because you have a passion for it. -- Marc Clifton My website