dasjo Posted March 8, 2005 Posted March 8, 2005 hello, i hope, i've chosen the right forum - wasn't shure about the decision. my problem: i have two classes: Category & Task every task belongs to a category here my task constructor: Public Sub New(ByVal valName As String, ByRef valCat As Cat) Name = valName Cat = valCat Cat.AddTask(Me) End Sub now i'd like to extend this constructor by adding a default category where to put the tasks if the tasks category is unknown. i don't know how to implement such a default category in the task constructor. it would be great if you could help me! thx greetz jo Quote
Administrators PlausiblyDamp Posted March 8, 2005 Administrators Posted March 8, 2005 Just add another constructor... Public Sub New(ByVal valName As String) Me.New(valName, "Default category name here") End Sub Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
jmcilhinney Posted June 9, 2005 Posted June 9, 2005 I know this is an old thread but I'm new here today and I was answering a question today on a different forum regarding overloading and optional parameters. While there is nothing wrong with overloading the constructor in this case, use of an optional parameter would be appropriate. You want a default category for when one is not provided and that is exactly what an optional parameter provides. The only issue might be that you need to declare the default value in the method definition, which might be impossible if your category is a complex object. Quote
Administrators PlausiblyDamp Posted June 9, 2005 Administrators Posted June 9, 2005 (edited) Personally I find overloaded functions easier and more flexible to use (intellisense provides better information for one) than relying on optional parameters. In this case creating an overloaded version was very little effort and would allow future expansion to the number of constructors to be considered without revisiting / rewriting the existing ones - if you had used an optional parameter this may not be the case. Also optional parameters are not supported across all .Net languages it can cause problems if you ever need to convert or work with things other than VB. Edited June 15, 2005 by PlausiblyDamp Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.