1 - no... more in a sec....
2 - basicaly, yes. Try looking up "polymorphism" The methods are not generic, as each class that does the implementation will have to provide the code, but the public signature will be EXACTLY the same between all classes that implement the interface.
3 - That's part of the beni, but not all.
Ok, now for #1. An interface is empty. It must be implemented by another class. If you don't implement it, you've got nothing to instanciate. The interface is a contract between two components. Basicaly one object says to the the other (I know it sounds like the begining of a joke doesn't it?) "Hey look, I agree to hold myself to the following interface. Rest assured that every PUBLIC method, property and function in the interface will exist in my object. I may not actualy have any code behind it, but the capability to call it will exist and you may do so w/o fear of an error."
Meanwhile the other object says to the first "You have agreed that you will have the following public methods, properties and functions. Rest assured that I will hold you to that standard, and will balk at the first sign that you haven't kept up your end of the bargan."
Let's see if I can pull this off.
Let's use a car analogy. Every car has an engine, but each manufacturer will build their engine differently. Infact, even within the same make, engines will be different - Think Chevy Nova vs a Chevy Truck.
So, if we were objectifying the car, we could have an interface that describes the methods and properties of the engine. We'll call it IEngine.
So in the EngineInterface class we have this:
Public Class EngineInterface
Interface IEngine
Property EngineSize() As Integer
Sub ApplyBrakes()
Sub Accelerate()
End Interface
End Class
Now we have our interfacve defined. There's no way to write code in there. It's just a shell.
If we then create a new class, ChevyNova and tell it to implement EngineInterface.IEngine... we get this:
Public Class ChevyNova
Implements EngineInterface.IEngine
Public Sub Accelerate() Implements EngineInterface.IEngine.Accelerate
End Sub
Public Sub ApplyBrakes() Implements EngineInterface.IEngine.ApplyBrakes
End Sub
Public Property EngineSize() As Integer Implements EngineInterface.IEngine.EngineSize
Get
End Get
Set(ByVal Value As Integer)
End Set
End Property
End Class
Now, here is where we write the code the dictates how a Chevy Nova would apply brakes, or accelerate, or what the engine size is.
Now, do the same for Lamborgini class:
Public Class Lamborgini
Implements EngineInterface.IEngine
Public Sub Accelerate() Implements EngineInterface.IEngine.Accelerate
End Sub
Public Sub ApplyBrakes() Implements EngineInterface.IEngine.ApplyBrakes
End Sub
Public Property EngineSize() As Integer Implements EngineInterface.IEngine.EngineSize
Get
End Get
Set(ByVal Value As Integer)
End Set
End Property
End Class
To use them, you simply Dim a variable as type EngineInterface.IEngine. Then you can use the .NET equivelent of CreateObject (the precise code escapes me at the moment) to set it to an instance of either the Nova or the Lamborgini class.
Is any of this helping?
-tg