Posts

Showing posts with the label overload

VB.NET: Overloading, shadowing and overriding

Spanish version / Versión en Español Overloading : When two methods have the same name, return type and different arguments (in type or quantity), we say they are overloaded. If their arguments are the same, they must be in different classes to avoid a duplicate definition. If those classes are unrelated, it's alright and we're still in the overload case. But if one class inherits from another, either Shadowing or Overriding can ocurr. Shadowing : This is what happens by default in VB.NET. Basically, the definition used when invoking is determined by the reference's type, not by the object's intrinsic type (the one with which it was created). In other word, there is no strict polymorphism/virtual mechanism. For example: Imports System Public Class Base Public Sub ShadowedSub() Console.WriteLine("ShadowedSub:Base") End Sub End Class Public Class Derived : Inherits Base Public Sub ShadowedSub() Console.WriteLine("...

VB.NET: Overloading, shadowing y overriding

Versión en inglés / English version Overloading : En general, hay overloading cuando dos o más métodos tienen el mismo nombre y devuelven lo mismo, pero los argumentos que reciben son diferentes en tipo y/o cantidad. Cuando nombre, tipo devuelto y argumentos coinciden, ello sólo puede ocurrir en clases diferentes para que no haya una definición duplicada. Si son clases sin relación, no hay problema. Pero si una hereda de otra, puede ocurrir Shadowing u Overriding. Shadowing : Esto es lo que ocurre por defecto en VB.NET. Básicamente, dado un objeto, no se llama la definición dada por su tipo intrínseco, sino por el aparente. En otras palabras, no hay polimorfismo. Ejemplo: Imports System Public Class Base Public Sub ShadowedSub() Console.WriteLine("ShadowedSub:Base") End Sub End Class Public Class Derived : Inherits Base Public Sub ShadowedSub() Console.WriteLine("ShadowedSub:Derived") End Sub End Class Public Class T...