I am looking for some different approaches to this following OOP scenario.
Dim pb As Object = Nothing
If radCars.Checked = True Then
Dim productBase As ProductsBase(Of CarColumns)
productBase = New Cars(fileLocation)
pb = productBase
ElseIf radTrucks.Checked = True Then
Dim productBase As ProductsBase(Of TruckColumns)
productBase = New Truck(fileLocation)
pb = productBase
End If
pb.Parse()
pb.AddRows()
....
Having to declare the object above and losing intelisense seems off. The base class if using generics because the Truck and Car classes use different column classes for the parsing and adding of columns in the db.
Base Class:
Public MustInherit Class ProductsBase(Of T)
Sub New(filePathString As String)
FilePath = filePathString
End Sub
MustOverride Sub Parse()
MustOverride Sub DeleteRows()
MustOverride Sub AddRows(ByVal rows As IEnumerable(Of T), pageNumber As Integer)
Property ParseResult As ProductLookupContainer(Of T)
End Class
Car Class:
Public Class Cars
Inherits ProductsBase(Of CarColumns)
Sub New(filePath As String)
MyBase.New(filePath)
End Sub
Public Overrides Sub AddRows(rows As IEnumerable(Of CarColumns), pageNumber As Integer)
DatabaseHelper.AddItemsToDB(Of CarProduct)(ConnectionString, rows, pageNumber)
End Sub
Public Overrides Sub DeleteRows()
DatabaseHelper.DeleteRows(ConnectionString, "CarProducts")
End Sub
Public Overrides Sub Parse()
Dim pf As New ParseFile(FilePath)
Dim result = New ProductLookupContainer(Of CarColumns)
result = pf.ParseCars
'Set object
ParseResult = result
End Sub
End Class