Now let??™s code a less trivial interface and see how classes
implement interface members:
Interface INonTrivial
Sub SomeMethod()
End Interface
Class A
Implements INonTrivial
Public Sub SomeMethod() Implements INonTrivial.SomeMethod
Console.WriteLine("Class A doing something.")
End Sub
End Class
Class B
Implements INonTrivial
Public Sub SomeMethod() Implements INonTrivial.SomeMethod
Console.WriteLine("Class B doing something.")
End Sub
End Class
Public Class EntryPoint
Shared Sub Main()
Dim ca As INonTrivial = New A
ca.SomeMethod()
Dim cb As INonTrivial = New B
cb.SomeMethod()
End Sub
End Class
The following shows the output of this program:
CHAPTER 6 n INTERFACES 99
Class A doing something.
Class B doing something.
In the example, each class implements INonTrivial??™s SomeMethod() to display a different
string. Each class uses an Implements statement
Implements INonTrivial
to specify that it??™s implementing the INonTrivial interface; and it uses an Implements clause
Public Sub SomeMethod() Implements INonTrivial.SomeMethod
to specify the interface member being implemented. VB declarative mapping tests this interface
contract via Implements INonTrivial.SomeMethod, and since the signatures match, you
can use a method name of your choice.
Pages:
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190