Prev | Current Page 175 | Next

Guy Fouch?©, Trey Nash

"Accelerated VB 2008"

Interfaces also make it easier for
you to add functionality to your types, while minimizing compatibility issues with existing clients.
Contracts, however, are not the only thing interfaces provide. Since Visual Basic (VB) does
not support inheritance from multiple types, but does allow types to implement multiple
interfaces, interfaces become a foundation for polymorphic programming.
Interfaces Are Reference Types
An interface defines a reference type, but, unlike classes, interfaces cannot be instantiated.
Classes and structures implement interfaces??”that is, they define the methods and other
members that formthe contract defined by the interface. Variables declared as an interface
type can hold a reference to any object that implements the interface.
Take a look at the following artificial but nonetheless typical pattern:
Public Interface IUIControl
Sub Paint()
End Interface
Public Class Button
Implements IUIControl
Public Sub Paint() Implements IUIControl.Paint
'Paint the Button
End Sub
End Class
Public Class ListBox
Implements IUIControl
Public Sub Paint() Implements IUIControl.Paint
'Paint the Listbox
End Sub
End Class 97
C H A P T E R 6
This example declares an interface named IUIControl that simply exposes one method,
Paint.


Pages:
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187
mieszkania dieta light katalog stron Altanki wierszyki