Say I have a database structure like this:
create table Product(id int not null identity,Name varchar(30))
INSERT INTO Product VALUES ('ProductA')
INSERT INTO Product VALUES ('ProductB')
and a class structure like this:
Imports System.Data.SqlClient
Public Class Product
Protected ProductName As String
Public Overridable Sub Display()
End Sub
End Class
Public Class ProductA
Inherits Product
Public Sub New(ByVal product As String)
ProductName = product
End Sub
Public Overrides Sub Display()
'Specific logic to display product A
End Sub
End Class
Public Class ProductB
Inherits Product
Public Sub New(ByVal product As String)
ProductName = product
End Sub
Public Overrides Sub Display()
'Specific logic to display product B
End Sub
End Class
Public Class Form1
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim p1 As Product
Dim p2 As Product
p1 = New ProductA("ProductA")
p2 = New ProductB("ProductB")
p1.Display()
p2.Display()
End Sub
End Class
There is a Property (Product) that identifies, which product the class relates to. This does not look correct to me. Is there a better way of modelling it? This is similar to the NHibernate concept of a Discriminator (I am not using NHibernate in this case).