Please let other users know how useful this tip is by rating it below. Do you have a tip or code of your own you'd...
like to share? Submit it here.
The ability to define interfaces has been introduced in Visual Basic .NET. VB6 supported interfaces too, but the way they were defined and used tended to raise the eyebrows of experienced object oriented programmers.
Interfaces have been the base of any object oriented programming languages. VB.NET and C# support multiple interface inheritance -- i.e., we can implement from more then one interface. Interfaces solve many problems associated with code reuse in object-oriented programming.
This code sample explains how to define an interface in VB.NET and how to implement the interface in other classes. There are a few constraints associated with interface; I will discuss those in later articles.
Imports System Imports Microsoft.VisualBasic Namespace n Public Interface MyInt Sub Mysub() Function MyFunc() As String End Interface Class mclass Implements MyInt ' Implement the above created interface Shared Sub Main() Dim o As New mclass() o.Mysub() End Sub 'This method maps to Mysub procedure in the interface Myint Sub Mysub() Implements Myint.Mysub msgbox("Hi") End Sub 'This method maps to MyFunc Function in the interface Myint Function MyFunc() As String Implements MyInt.MyFunc 'Do something and return a value End Function End Class End Namespace