Declaring Sub

  • Thread starter Thread starter Fabio
  • Start date Start date
F

Fabio

Hi all,

Whats the real difference between Overloads and Shadows in a Sub????

Thanks in advance,

Fabop
 
Fabio,

an overloads method is the same member type (sub, function, property,
etc...)
a Shadows method has the same name, but is either a diferent member type, or
a function with an incompatible return type.

Basicly, Overloads offers another choice to the developer using the class
(both methods are available), Shadows hides the base class member(only the
Shadows member is available).

Kirk Graves
 
You use Overloads when you want to declare multiple versions of the same
method that take different parameters.
Shadows is used to make you method replace the same one that is implemented
by your base class. In this case your base class did not declare the method
with Overridable (virtual), so you cannot use the Overrides keyword in your
method declaration.
 
Hi Fabio,

Overloading a method allows you to specify multiple versions of the same
method, but with a different parameter signature:

Public Overloads Sub ShowMessge(ByVal Text As String)
'
End Sub

Public Overloads Sub ShowMessage(ByVal Number As Integer)
'
End Sub

Public Overloads Function ShowMessage(ByVal Number As Integer, ByVal Text As
String) As Boolean
'
End Sub

You can overload the return type of a method, as long as the parameters are
different to any other overloaded version.

Shadowing isn't *really* related to Overloading (perhaps you meant
overriding?), however it is linked due to the fact that you can overload a
version of a method in a base class, with a new version in the derived class

Public Class MyBaseClass
Public Sub MySub()
'
End Sub
End Class

Public Class MyDerivedClass
Inherits MyBaseClass

Public Shadows Function MySub(Argument As String) As Integer
'
End Sub
End Class

* or *

Public Class MyBaseClass
Public Sub MySub()
'
End Sub
End Class

Public Class MyDerivedClass
Inherits MyBaseClass

Public Overloads Function MySub(Argument As String) As Integer
'
End Sub
End Class

They are both valid because the parameters are different.

The shadows clause, when attached to a method declaration allows you to
replace a method that's declared in a base class, with a new version, in the
new class. It does not override the base method, and so you can specify a
different access level, or return type, or parameters. This means you can
create a new version of a method that replaces a method in the base class
that is not declared as overridable.

--
HTH,
-- Tom Spink, Über Geek

Please respond to the newsgroup,
so all can benefit

" System.Reflection Master "

==== Converting to 2002 ====
Remove inline declarations
 
Back
Top