This is a general question about Object Orientation and specifically overloading functions in .NET (or any other framework or language). I am looking at an application that has a lot of duplicate code. For example, have a look at the following functions:
Public Function Test(ByVal Test1 As String)
//code that is specifically relevant to Test1 variable
End Function
Public Function Test (ByVal Test1 As String, ByVal Test2 As String)
//code that is specifically relevant to Test1 variable
//code that is specifically relevant to Test2 variable
End Function
I would of thought that best pratice would be to put: //code that is specifically relevant to Test1 variable in a separate function as it is common in both functions. Is this the case? I have always thought that duplicate code is a very bad idea.
It is not better:
Overloading ideally should be about adding aditional features to the original function but preserving it’s original behaviour in case you use it somewhere else in your code.