Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Sub names
Message
From
14/02/2011 08:54:32
 
 
To
14/02/2011 08:29:11
General information
Forum:
ASP.NET
Category:
Other
Title:
Miscellaneous
Thread ID:
01500059
Message ID:
01500067
Views:
45
>>>>>Hi
>>>>>
>>>>>I've found in one of the modules I'm looking at there are duplicate sub routine names (below)
>>>>>I'm suprised this isn't flagged as an error.
>>>>>
>>>>>Is this permissible in .NET. It seems quite confusing to me.
>>>>>
>>>>>Nick
>>>>>
>>>>>
>>>>>
>>>>>Private Sub plotPointBounce(ByVal monthRow As DataRow, ByVal seriesName As String)
>>>>>
>>>>>Private Sub plotPointBounce(ByVal month As DateTime, ByVal seriesName As String, ByVal bounceRate As Double, _
>>>>> ByVal inWarrantyRatio As Double)
>>>>
>>>>Standard method overloading... If the parameters are different then the signature is different. It would be likely that a call to the first example will simply add some default values for bounceRate and inWarrantyRatio before calling the second.
>>>
>>>I see that
>>>
>>>But if you always go through A to get to B why bother.
>>
>>But you don't *always* go through A to get to B. If you have something like this:
   Private Sub plotPointBounce(ByVal monthRow As DataRow, ByVal seriesName As String)
>>        Dim dt As DateTime = DirectCast(monthRow("DT"), DateTime)
>>        plotPointBounce(dt, seriesName, 0, 0)
>>    End Sub
>>
>>    Private Sub plotPointBounce(ByVal month As DateTime, ByVal seriesName As String, ByVal bounceRate As Double, _
>> ByVal inWarrantyRatio As Double)
>>    End Sub
then you can call the second version directly with a different date and specific values for the last two parameters. Of course if you were always passing the same last two values from the first version you could make the final two parameters in the second version optional and drop them from the first version completely:
   Private Sub plotPointBounce(ByVal monthRow As DataRow, ByVal seriesName As String)
>>        Dim dt As DateTime = DirectCast(monthRow("DT"), DateTime)
>>        plotPointBounce(dt, seriesName)
>>    End Sub
>>
>>    Private Sub plotPointBounce(ByVal month As DateTime, ByVal seriesName As String, _
>> Optional ByVal bounceRate As Double = 0, Optional ByVal inWarrantyRatio As Double = 0)
>>    End Sub
>
>I see it
>
>But I guess as I'm still new at .NET I still find out counter intuitive.
>
>I would definitely trend towards having one routine with optional parameters.
>
>But thanks.

I think you may be missing the potential benefits. Assume the first method got *most* of it's parameters from a DataRow:
Private Sub plotPointBounce(ByVal monthRow As DataRow, ByVal seriesName As String)
        Dim dt As DateTime = DirectCast(monthRow("DT"), DateTime)
        Dim bounce As Double = DirectCast(monthRow("Bounce"), Double)
        Dim warranty As Double = DirectCast(monthRow("Warranty"), Double)
        plotPointBounce(dt, seriesName, bounce, warranty)
    End Sub
You can just call that with plotPointBounce(dr,s) from multiple places. If you sometimes need to perform the same action but the data is in, say, an XmlElement then you can add a similar method that accepts the XmlElement instead of the DataRow.
Also, if the DataRow changes you can adapt the method content in one place rather than modifying each individual call to the 'concrete' method.
Previous
Reply
Map
View

Click here to load this message in the networking platform