Prev | Current Page 177 | Next

Guy Fouch?©, Trey Nash

"Accelerated VB 2008"

For example, in the following
code
Interface IUIControl
Sub Paint()
End Interface
IUIControl has only one member, the method Paint, and it uses only a Sub statement to
declare it, without providing a method body or an End Sub statement.
Interfaces, like classes, default to Friend accessibility in a namespace, but you can also
declare them Public.Within classes, modules, interfaces, and structures, they default to Public,
but they can also be Friend, Protected, or Private. Interface members are implicitly Public and
may not have access modifiers.
nNote By convention, interface names start with I.
Let??™s code a trivial interface to get familiar with how you declare and use interfaces:
Interface ITrivial
End Interface
Class A
Implements ITrivial
End Class
CHAPTER 6 n INTERFACES 98
Class B
Implements ITrivial
End Class
Public Class EntryPoint
Shared Sub Main()
Dim ca As ITrivial = New A
Dim cb As ITrivial = New B
End Sub
End Class
ITrivial is as trivial as an interface can get. Class A and Class B both implement it, but
trivially, since it has no members to implement. However, by implementing ITrivial, you can
store instances of both Class A and Class B in ITrivial variables. This is an example of how
interfaces support polymorphism.


Pages:
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189
House Extension Kąty Rybackie noclegi kasyno Kołobrzeg plecaki