I watched Anders' Story about C # 4.0 and a preview of C # 5.0 , and I wondered when additional C # parameters were available, what would be the recommended way to declare methods that don't need all of the specified parameters?
For example, something like the FileStream class has about fifteen different constructors that can be divided into logical “families”, for example. those listed below are from the IntPtr line and those from SafeFileHandle .
FileStream(string,FileMode); FileStream(string,FileMode,FileAccess); FileStream(string,FileMode,FileAccess,FileShare); FileStream(string,FileMode,FileAccess,FileShare,int); FileStream(string,FileMode,FileAccess,FileShare,int,bool);
It seems to me that this type of template can be simplified by using three constructors and using optional parameters for those that may be defaulted, which would make the different families of constructors more clear [note: I know this change will not be made in BCL, I'm hypothetically talking about this type of situation].
What do you think? From C # 4.0, would it be more appropriate to create closely related groups of constructors and methods with a single method with optional parameters, or is there a good reason to stick to the traditional multi-load mechanism?
Greg Beech Oct 30 '08 at 21:42 2008-10-30 21:42
source share