An interface is just a container for "rules". These rules may include
method, property, event declarations, etc. but do not include any actual
functional code.
Implementing an interface is an agreement to follow the "rules" specified in
the interface. Any class that implements the ISynchronizeInvoke interface,
for example, must also now implement any of the things defined in that
interface (like an Invoke method). It is up to the class that is
implementing the interface to determine what will actually happen when the
Invoke method is called.
A simplified analogy would be that a car's interface includes having a
steering wheel, a gear shifter and the abilities to accelerate and
decelerate. If you were going to build a car, then you'd need to implement
this standard interface (because obviously a car has to have the previously
mentioned things), BUT it would be up to you (the creator of the car) to
determine exactly what kind of steering wheel and gear shifter you wanted
and it would also be up to you to determine exactly HOW you want to
IMPLEMENT the functionality for accelerating and decelerating.
For example:
Public Interface Automobile
Property CurrentGear() As Integer
Sub Accelerate(ByVal ByHowMuch As Short)
Sub Decelerate(ByVal ByHowMuch As Short)
End Interface
Public Class Car
Implements Automobile
Public Sub Accelerate(ByVal ByHowMuch As Short) Implements
Automobile.Accelerate
'Now, you decide exactly how to make this happen
End Sub
Public Property CurrentGear() As Integer Implements Automobile.CurrentGear
Get
'Now, you decide exactly how to make this happen
End Get
Set(ByVal Value As Integer)
'Now, you decide exactly how to make this happen
End Set
End Property
Public Sub Decelerate(ByVal ByHowMuch As Short) Implements
Automobile.Decelerate
'Now, you decide exactly how to make this happen
End Sub
End Class
-Scott
"Rulin Hong" <Ru*******@discussions.microsoft.com> wrote in message
news:7E**********************************@microsof t.com...
According to OO, interface is just a bunch of definitions, no
implementation
at all. It's also true when we write our own code in .NET. But I find
every
interface provided by .NET has specific implementation.
For example. Control.Invoke Method Executes a delegate on the thread that
owns the control's underlying window handle because it is implemented
ISynchronizeInvoke.Invoke.
Why?
Thanks in advance