¿Cuáles son las diferencias de comportamiento para la propiedad Previous
de Other1
y Other2
Clase.Sobrecargas y anulaciones en VB.net
Nota que el tipo de retorno de la sobrecarga Previous
Propiedad de Other2
se ha cambiado a Other2
mientras se mantiene como Base
para Other1
.
Public Class Base
Private _Previous as Base
Protected Overridable ReadOnly Property Previous As Base
Get
Return _Previous
End Get
End Property
Public Sub New(Previous as Base)
_Previous = Previous
End Sub
End Class
Public Class Other1
Inherits Base
Private _Parent as SomeType
Protected Overrides ReadOnly Property Previous As Base
Get
Return _Parent.Previous.Something
End Get
End Property
Public Sub New(Parent as SomeType)
MyBase.New(Nothing)
_Parent = Parent
End Sub
End Class
Public Class Other2
Inherits Base
Private _Parent as SomeType
Protected Overloads ReadOnly Property Previous As Other2
Get
Return _Parent.Previous.Something
End Get
End Property
Public Sub New(Parent as SomeType)
MyBase.New(Nothing)
_Parent = Parent
End Sub
End Class
Parece que la palabra clave 'Shadows' puede convertirse muy fácilmente en una grave violación de LSP. – Panzercrisis