Parameters
The concept of passing parameters is nothing new to OOP, and certainly not an incredibly difficult concept to grasp, since the same techniques were used when programming ASP/VB parameterized subroutines and functions. And what exactly are parameters? Values.
Shortly, as we explore Overloading , you'll simultaneously gain knowledge of this concept as well, if you didn't already.
Method Overloading
Method Overloading or Overloading is the means of re-implementing a method with the same name numerous times, providing its signatures (or number of parameter and or parameter reference types) are different.
To demonstrate, we'll now overload our ShowStats()
method (taken from the Inheritance section code example) two different ways. Right after the default ShowStats method you can create overloaded methods, ready for implementation depending on your purpose like so:
public string ShowStats(string StartTxt){
return base.Summary() + " - " + StartTxt + " it is located in " + Loc;
}
public object ShowStats(string StartTxt, string EndTxt){
return base.Summary() + " - " + StartTxt + " it is located in " + Loc + " - " + EndTxt;
}
Our default ShowStats()
method as noted before is the standard non-overloaded method. Above however, we've added an additional two methods, both overloading our default method. The first one a string
method, accepts only one parameter StartTxt
, thus its signature distinguishes it from its predecessor. The second pushes further by being an object
method with two parameters , StartTxt
and EndTxt
. Both retrieving Loc from before as well.
And in our .aspx page we implement it, in addition to the way we did before, like this:
//Overloaded method 1
Response.Write (oHouse.ShowStats(" I think ") + "<BR><BR>");
//Overloaded method 2
Response.Write (oHouse.ShowStats(" I'm sure "," That's cool! ") + "<BR><BR>");
Same name, different signatures thus overloading, and our results:
Comments