Prev | Current Page 81 | Next

Guy Fouch?©, Trey Nash

"Accelerated VB 2008"


Interfaces
Even though much of Chapter 6 is devoted to the topic of interfaces, it is worth introducing
interfaces at this point for the purposes of discussion in the rest of this chapter. Generally speaking,
an interface is a definition of a contract. Classes can choose to implement various interfaces,
and by doing so, they guarantee to adhere to the rules of the contract. When a class inherits from
an interface, it is required to implement the methods of that interface. A class can implement as
many interfaces as it wants by listing them in the interface list of the class definition.
In general terms, an interface??™s syntax closely resembles that of a class. However, each
member is implicitly Public. Interfaces can only contain instance methods; therefore, you
can??™t include any Shared methods in the definition. Interfaces don??™t include an implementation;
interfaces don??™t contain any internal code, so they are semantically abstract in nature.
The members of an interface can only consist of members that ultimately boil down to
methods in the CLR. This includes methods, properties, and events. The following code shows
an example of an interface and a class that implements the interface:
'NOTE: Standard practice is that you preface Interface with a capital "I"
Public Interface IMusician
Sub PlayMusic()
End Interface
Public Class TalentedPerson
Implements IMusician
Public Sub PlayMusic() Implements IMusician.


Pages:
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
życzenia katalog stron katalog stron pozycjonowanie Connie Talbot