What is an Interface?

Interfaces help to define the various properties, methods and events that classes are able to implement. For developers these fine a small group of closely related properties, methods, and events. Additional feature and functionality can be added at any by adding additional interfaces and implementations. Prior to .NET Visual Basic was able to consume interfaces but not able to create them directly. With Visual Basic.NET the INTERFACE statement was introduced. This statement allows the definition of a true interface as a distinct entity from classes and to implement them using the IMPLEMENTS keyword. The following is a simple example of creating a CustomerManagement interface.

Public Class Customer

Interface CustomerManagement

Function AddCustomer(ByVal CustomerName As String, ByVal CustomerAddress As String, ByVal CustomerContact As String)

Function DeleteCustomer(ByVal CustomerName As String)

Function UpdateCustomer(ByVal CustomerName As String, ByVal CustomerAddress As String, ByVal CustomerContact As String)

End Interface

End Class

This interface is implemented by using the IMPLEMENTS keyword as shown below.

Once implemented the defined interface contains all the functions defined within the interface. Like a class, interfaces define a set of properties, methods and events. However, unlike classes, interfaces provide no direct implementation. They are implemented by classes defined as a separate entity from classes. Metaphorically, an interface represents a contract. Within this contract a class that implements an interface agrees to implements every aspect of that interface exactly as it is defined.

It is important to remember that interface implementations are allowed to evolve. However, the interfaces themselves shouldn’t be changed once they are published. Changes to the interface may break existing code that has implemented the interface. Once again, like a contract both parties in the contract agree never to change that implemented interface

Comments (1)

  1. I like this post. I think it is important to get information like this out – not everyone out there is a world-class expert and many people that are moving to .NET from earlier incarnations of VB, etc. can benefit from this type of information. Very clear, concise description!


Skip to main content