C
Christopher W. Douglas
I am developing a VB.NET app using Visual Studio.NET 2003. VB.NET allows
me to create a class with two or more methods that have the same name, as
long as they have different (non-optional) arguments, such as:
FirstClass
Public Sub Populate(string)
Public Sub Populate(string, string)
I don't have to use Overloads, because both methods are in the same class.
I also understand that through inheritance, I can have a class that
derives from a base class, and the derived class inherits methods:
BaseClass
Public Sub Populate(string)
FirstClass
(Has Populate(string) available)
Now, if I need to replace the Populate method in another class, I use
Protected and Overrides:
BaseClass
Protected Overridable Sub Populate(string)
FirstClass
(Has Populate(string) available)
SecondClass
Public Overrides Sub Populate(string)
* different code here *
Through what I *think* is polymorphism, I can have another class call the
Populate method of either FirstClass or SecondClass:
OtherClass
PopulateClass(a as BaseClass, mystring as String)
a.Populate(mystring)
PopulateClass can be passed either a FirstClass or a SecondClass object, and
the populate method will be called.
Now, what I want to do is have two methods with the same name but
different signatures, such as:
BaseClass
Protected Sub Populate(string)
FirstClass
(Has Populate(string) available)
SecondClass
Public Overloads? Overrides? Shadows? Sub Populate(string)
Populate Overloads? Overrides? Shadows? Sub Populate(string, integer,
integer)
The trouble is, I can't figure out whether to use Shadows, Override or
Overloads. I get an error if I only use Shadows on one method, and the
*base* method is called if I use Overrides or Overloads. Can someone help
me out here?
me to create a class with two or more methods that have the same name, as
long as they have different (non-optional) arguments, such as:
FirstClass
Public Sub Populate(string)
Public Sub Populate(string, string)
I don't have to use Overloads, because both methods are in the same class.
I also understand that through inheritance, I can have a class that
derives from a base class, and the derived class inherits methods:
BaseClass
Public Sub Populate(string)
FirstClass
(Has Populate(string) available)
Now, if I need to replace the Populate method in another class, I use
Protected and Overrides:
BaseClass
Protected Overridable Sub Populate(string)
FirstClass
(Has Populate(string) available)
SecondClass
Public Overrides Sub Populate(string)
* different code here *
Through what I *think* is polymorphism, I can have another class call the
Populate method of either FirstClass or SecondClass:
OtherClass
PopulateClass(a as BaseClass, mystring as String)
a.Populate(mystring)
PopulateClass can be passed either a FirstClass or a SecondClass object, and
the populate method will be called.
Now, what I want to do is have two methods with the same name but
different signatures, such as:
BaseClass
Protected Sub Populate(string)
FirstClass
(Has Populate(string) available)
SecondClass
Public Overloads? Overrides? Shadows? Sub Populate(string)
Populate Overloads? Overrides? Shadows? Sub Populate(string, integer,
integer)
The trouble is, I can't figure out whether to use Shadows, Override or
Overloads. I get an error if I only use Shadows on one method, and the
*base* method is called if I use Overrides or Overloads. Can someone help
me out here?