Figure 1 Inheritable Class
Class Class1
Overridable Sub Foo()
'*** method definition
End Sub
End Class
'*** your class
Class Class2 : Inherits Class1
Overrides Sub Foo()
'*** method definition
End Sub
End Class
'*** another programmer's class
Class Class3 : Inherits Class2
'*** can this class override Foo?
End Class
Figure 2 Using NotOverridable
Class Class1
Overridable Sub Foo()
'*** method definition
End Sub
End Class
'*** your class
Class Class2 : Inherits Class1
NotOverridable Overrides Sub Foo()
'*** method definition
End Sub
End Class
'*** another programmer's class
Class Class3 : Inherits Class2
'*** this class cannot override Foo
End Class
Figure 3 One Foo, Many Calling Methods
Class Class1
Overridable Sub Foo()
'*** method definition
End Sub
End Class
Class Class2 : Inherits Class1
Overrides Sub Foo()
'*** method definition
End Sub
Sub Bar()
MyBase.Foo() '*** uses static binding to call Class1.Foo
MyClass.Foo() '*** uses static binding to call Class2.Foo
Me.Foo() '*** uses dynamic binding to call Class3.Foo
Foo() '*** uses dynamic binding to call Class3.Foo
End Sub
End Class
Class Class3 : Inherits Class2
Overrides Sub Foo()
'*** method definition
End Sub
End Class
Figure 4 Deriving from Class1
Interface IFooable
Sub Foo()
End Interface
Class Class1 : Implements IFooable
Sub Foo() Implements IFooable.Foo
'*** method definition
End Sub
End Class
'*** Class2 implicitly implements IFooable
Class Class2 : Inherits Class1
'*** can this class override IFooable.Foo?
End Class
Figure 5 Foo Declared as Overridable
Interface IFooable
Sub Foo()
End Interface
Class Class1 : Implements IFooable
Overridable Sub Foo() Implements IFooable.Foo
'*** method definition
End Sub
End Class
Class Class2 : Inherits Class1
Overrides Sub Foo()
'*** method definition
End Sub
End Class
Figure 6 Foo Declared as Protected
Interface IFooable
Sub Foo()
End Interface
Class Class1 : Implements IFooable
Protected Overridable Sub Foo() Implements IFooable.Foo
'*** method definition
End Sub
End Class
Class Class2 : Inherits Class1
Protected Overrides Sub Foo()
'*** method definition
End Sub
End Class
Figure 7 Concrete Class Inherits from Abstract Class
MustInherit Class Person
MustOverride Sub Speak()
'*** other definition details omitted for clarity
End Class
Class Programmer : Inherits Person
Overrides Sub Speak()
'*** programmer-specific implementation
End Sub
End Class
Class Administrator : Inherits Person
'*** does not compile - no implementation for Speak
End Class
|