E
eje
I'm trying to understand class hierarchies in VB .NET.
I'm designing an application where data come in textfiles
from different sources and will be stored in a database.
To avoid future problems the importdata must be well
validated. There are several tables and fields in the
database. My idea is to have some 'baseclasses' with one
property (value) and one validatingfunction to validate
the value before it is accepted. (See class StringBase
below) A limited number of 'baseclasses' where each
normally could be used for more than one field should
cover all my needs. Next step would be to build one class
per databasetable. (See class Car below). These classes
could finally be used in the importprocedures. (See class
ImportVehicleData, Sub ImportCarData below).
My problem is that Validate and Value are not available
as I have designed the Sub ImportCarData. If I dim Name
and Color instead of Car it's no problem but then I loose
much of my design idea. The .NET framework has an endless
number of derived classes with properties and methods so
I think it must be possible to solve my problem too. (The
code below is only an example to describe my problem.)
Public Class StringBase
Public Property Value() As String
. . .
End Property
Public Overridable Function Validate(ByVal value) As
Boolean
'Validate Len(value) <= 10. Return True if OK
. . .
End Function
End Class
Public Class Car
Public Sub New()
End Sub
Public Class Name
Inherits StringBase
End Class
Public Class Color
Inherits StringBase
End Class
End Class
Public Class ImportrVehicleData
Sub ImportCarData()
Dim Data As New Car
'Get first data
If Data.Name.Validate(value) Then
Data.Name.Value = value
Else
'Do something
End If
'Get next data
If Data.Color.Validate(value) Then
Data.Color.Value = value
Else
'Do something
End If
'If all data OK send data to database
End Sub
. . .
End Class
Thanks for any help
Eje
I'm designing an application where data come in textfiles
from different sources and will be stored in a database.
To avoid future problems the importdata must be well
validated. There are several tables and fields in the
database. My idea is to have some 'baseclasses' with one
property (value) and one validatingfunction to validate
the value before it is accepted. (See class StringBase
below) A limited number of 'baseclasses' where each
normally could be used for more than one field should
cover all my needs. Next step would be to build one class
per databasetable. (See class Car below). These classes
could finally be used in the importprocedures. (See class
ImportVehicleData, Sub ImportCarData below).
My problem is that Validate and Value are not available
as I have designed the Sub ImportCarData. If I dim Name
and Color instead of Car it's no problem but then I loose
much of my design idea. The .NET framework has an endless
number of derived classes with properties and methods so
I think it must be possible to solve my problem too. (The
code below is only an example to describe my problem.)
Public Class StringBase
Public Property Value() As String
. . .
End Property
Public Overridable Function Validate(ByVal value) As
Boolean
'Validate Len(value) <= 10. Return True if OK
. . .
End Function
End Class
Public Class Car
Public Sub New()
End Sub
Public Class Name
Inherits StringBase
End Class
Public Class Color
Inherits StringBase
End Class
End Class
Public Class ImportrVehicleData
Sub ImportCarData()
Dim Data As New Car
'Get first data
If Data.Name.Validate(value) Then
Data.Name.Value = value
Else
'Do something
End If
'Get next data
If Data.Color.Validate(value) Then
Data.Color.Value = value
Else
'Do something
End If
'If all data OK send data to database
End Sub
. . .
End Class
Thanks for any help
Eje