Overloading is a feature that will allow an object's methods and operators to have different meanings depending on its context. Operators can behave differently depending on the data type, or class, of the operands. For example, x+y can mean different things depending on whether x and y are integers or structures. Overloading is especially useful when your object model dictates that you employ similar names for procedures that operate on different data types. For example, a class that can display several different data types could have display procedures that look like this:
Overloads Sub Display (theChar As Char)
...
Overloads Sub Display (theInteger As Integer)
...
Overloads Sub Display (theDouble As Double)
Without overloading, you'd have to create distinct names for each procedure even though they do the same thing:
Sub DisplayChar (theChar As Char)
...
Sub DisplayInt (theInteger As Integer)
...
Sub DisplayDouble (theDouble As Double)
Comments