Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

  • 3 months later...
Posted
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.
  • Administrators
Posted (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 by PlausiblyDamp

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...