Shouldn't interface objects have the basic methods of an object, like GetType, Equals, etc.? For instance, in the following code I have to had quite a bit extra to tell if the two objects are of the same class. Maybe the answer is that I should be using inheritance instead of an interface here, but still, logically it seems surprising that you can't use all the basic methods of an object on an object referenced like this.
Visual Basic:
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim p As INameObject
p = New class1
Debug.Print(TypeName(p))
Dim c As INameObject
c = New class2
Debug.Print(c.FnGetType Is p.FnGetType)
' Debug.Print(c.gettype Is p.gettype) 'Can't say this.
End Sub
End Class
Public Interface INameObject
Property Name() As String
Function FnGetType() As Type
End Interface
Public Class class1
Implements INameObject
Private pName As String
Public Property Name() As String Implements INameObject.Name
Get
Return pName
End Get
Set(ByVal value As String)
pName = value
End Set
End Property
Public Function FnGetType() As System.Type Implements INameObject.FnGetType
Return Me.GetType
End Function
End Class
Public Class class2
Implements INameObject
Private pName As String
Public Property Name() As String Implements INameObject.Name
Get
Return pName
End Get
Set(ByVal value As String)
pName = value
End Set
End Property
Public Function FnGetType() As System.Type Implements INameObject.FnGetType
Return Me.GetType
End Function
End Class