Rulin Hong said:
Scott M.
I know what you said.
I give you another example, Postback Event of web server control. Here is
the code.
Namespace CustomControls
Public Class MyButton
Inherits Control
Implements IPostBackEventHandler
' Defines the Click event.
Public Event Click As EventHandler
' Invokes delegates registered with the Click event.
Protected Overridable Sub OnClick(e As EventArgs)
RaiseEvent Click(Me, e)
End Sub
' Method of IPostBackEventHandler that raises change events.
Public Sub RaisePostBackEvent(eventArgument As String) Implements
IPostBackEventHandler.RaisePostBackEvent
OnClick(EventArgs.Empty)
End Sub
Protected Overrides Sub Render(output As HtmlTextWriter)
output.Write("<INPUT TYPE=submit name=" & Me.UniqueID & _
" Value='Click Me' />")
End Sub
End Class
End Namespace
In this code, we just simply write
Implements IPostBackEventHandler.RaisePostBackEvent.
There is none of code about how to postback. In other words, I guess .NET
must have something behind IPostBackEventHandler.RaisePostBackEvent.
No. This class "implements" an interface. Therefore, specific
implementation of the interface IS required. The interface definition
itself does NOT contain the code for the methods/properties/et cetera, but
implementing class(es) do...ex:
' The following interface contains no implementation code:
Public Interface IShape
Property Width() As Double
Function CalculateArea() As Double
End Interface
' The following class contains implementation code for the IShape interface
declared above.
Public Class Triangle
Implements IShape
Public Function CalculateArea() As Double _
Implements IShape.CalculateArea
' Calculate the area of the triangle here.
End Function
Public Property Width() As Double Implements IShape.Width
Get
' Return the width.
End Get
Set(ByVal Value As Double)
' Set the width.
End Set
End Property
End Class
HTH,
Mythran