これが数か月前に投稿されたことは知っていますが、おそらく完全を期すために、返信を試みるつもりです.
クラス内からオーバーライドされたメソッドにアクセスでき、dog
別の名前で公開できると言われました。しかし、条件式を使用するのはどうですか?
あなたはただ行うことができます:
Public Class Animal
Public Overridable Function Speak(Optional ByVal speakNormal as Boolean = False) As String
Return "Hello"
End Function
End Class
Public Class Dog
Inherits Animal
Public Overrides Function Speak(Optional ByVal speakNormal as Boolean = False) As String
If speakNormal then
return MyBase.Speak()
Else
Return "Ruff"
End If
End Function
End Class
そして、次のように呼び出します。
Dim dog As New Dog
Dim animal As new Animal
animal.Speak() //"Hello"
dog.Speak()//"Ruff"
dog.Speak(true)//"Hello"
または、次のようにgetTheAnimalInTheDog
すること Speak()
もできます。
あなたはただ行うことができます:
Public Class Animal
Public Overridable Function Speak() As String
Return "Hello"
End Function
Public MustOverride Function GetTheAnimalInMe() As Animal
End Class
Public Class Dog
Inherits Animal
Public Overrides Function Speak() As String
Return "Ruff"
End Function
Public Overrides Function GetTheAnimalInMe() As Animal
Dim a As New Animal
//Load a with the necessary custom parameters (if any)
Return a
End Function
End Class
そして再び:
Dim dog As New Dog
Dim animal As new Animal
animal.Speak() //"Hello"
dog.Speak()//"Ruff"
dog.GetTheAnimalInMe().Speak()//"Hello"
それが役に立てば幸い ;)