Interfaces

Unknown | 12:38 AM |

An interface is like an abstract class which allows the derived class to inherit
more than one interfaces into it.
We have already seen an abstract class can have methods with or without
implementation. But an interface can only have members without
implementation. So it provides only structure of the objects like abstract class.
To implement an interface in VB.NET, we use the keyword Implements and we
must provide implementations for all the methods of the interface we implements.
Defining an Interface:- Interfaces are declared with the following structure
Public Interface <Name of the interface>
:
<decleration of memebrs of the interface, means methods and properties
structure>
:
End Interface
Let us take up a example and see how the declaration been done
Interface IShape
Sub Draw(ByVal coord() As ArrayList)
End Interface
interface IShape
{
void Draw(ArrayList coord);
}
Implementation of Interface:- Interfaces are implemented using Implements keyword. All the
members of the interface are implemented with Implements keyword.
“To implement a interface, we must implement all the methods and properties defined by the
interface”
If more than one interface is to be implemented, then interfaces names should separated by
commas with the implements keyword while defining a class.
Lets us take an example of implementation:-
Public Class Drawing
Implements Ishape
Public Sub Draw(ByVal parCoord() As ArrayList) Console.Write("Draw a Circle")
End Sub
End Class
Public Class Drawing: Ishape
{
Public void Draw (ArrayList parCoord)
{
Console.Write("Draw a Circle");
}
}
In the example, we are implementing Isahpe interface, which contains Draw method into the
Drawing Class.

Category:

About http://dotnetvisual.blogspot.in/:
DOT NET TO ASP.NET is a web application framework marketed by Microsoft that programmers can use to build dynamic web sites, web applications and web services. It is part of Microsoft's .NET platform and is the successor to Microsoft's Active Server Pages (ASP) technology. ASP.NET is built on the Common Language Runtime, allowing programmers to write ASP.NET code using any Microsoft .NET language. create an application very easily ....