Hello All,
I have two classes, only the type of one of the properties is different.
How should I declare the two classes?
For example:
I want to declare 2 Classes, named MySQLIntfield and MySQLStrField. Both
have the Name and Value properties, but one of the type of value
property is string and the other is Int.
Their Methods are common, like get NameValue string or getNameValue xml
string.
I listed my code below. But I don't like the idea to declare mValue as
object. Is there any other way?
Many thanks.
Gary
-----------------------------------------------------
Class MySQLField
Protected mName As String
Protected mValue As Object
Property SQLName() As String
Get
Return mName
End Get
Set(ByVal Value As String)
mName = Value
End Set
End Property
ReadOnly Property NameValue()
Get
Return mName.ToString + mValue.ToString
End Get
End Property
'I try to declare like this, but doesn't work.
'The error message is:
'can not overload each other, because they differ
'only return types.
'MustOverride Property Value() as object
End Class
Class MySQLIntField
Inherits MySQLField
Property Value() As Int16
Get
Return CType(mvalue, Int16)
End Get
Set(ByVal Value As Int16)
mvalue = Value
End Set
End Property
End Class
Class MySQLStringField
Inherits MySQLField
Property Value() As String
Get
Return CType(mvalue, String)
End Get
Set(ByVal Value As String)
mvalue = Value
End Set
End Property
End Class