Like classes, interfaces define properties, methods, and events of an object. Unlike classes, interfaces do not provide any implementation, and you cannot create an instance of an interface. A class can implement one or more interfaces.

Any class that implements an interface must implement all the members of the interface as they are defined. An interface should not change after it has been deployed in your solution, because any such change could possibly break existing code.

You declare interfaces using the Interface statement. For example, the code in Listing 3.11 defines an interface that must be implemented with a method that takes an Integer argument and returns an Integer. When you implement this interface in a class, the data type for the arguments and the return value of the method must match those of the method defined (in this case, Integer). You can implement this interface within a class by using the Implements keyword, as shown in Listing 3.11.

Listing 3.11. Creating and implementing an interface

Public Interface ISampleInterface

Function SampleFunction(ByVal Count As Integer) As Integer End Interface

Public Class SampleClass

Implements ISampleInterface

Function SampleFunction(ByVal Count As Integer) As Integer _ Implements ISampleInterface.SampleFunction

' Add code to perform the function here. End Function

End Class

0 0

Post a comment