G
Guest
Accidently posted this to the wrong group so I am reposting.
This is probably a newbie question but I am a little confused about how to go
next with my code. I think I want to use a factory pattern in this situation
but I am having trouble getting access to properties at the presentation
level. So my situation is I have a Vehicle base class.
Public Class Vehicle
Property BodyType as String
End Class
Then I have multiple inherited Classes
Public Class Truck inherits Vehicle
Property Weight as String
End Class
Public Class Forklift inherits Vehicle
Property EngineType as String
End Class
My factory uses a select statement on the Body Type to decide which class to
instantiate.
Public Class VehicleFactory
Public Shared Function CreateVehicleInstance(bodyType as String) as Vehicle
Select Case bodyType
Case "Truck"
return v as New Truck
Case "Forklift"
return v as New Forklift
End Select
return v
End Function
End Class
My problems comes when I try return my class from the factory and access
properties of the inherited class. The compiler won't let me compile it and I
am not sure where to go. So for exampl
Dim v as Vehicle = VehicleFactory.CreateVehicleInstance("Truck")
v.Weight = 6 'this give me a compile error that Weight is not a member of
the base class
I am trying to use this on the form and once the object is created then I
need it accesible to the form to track whether it needs to be saved back to
the database or not. Am I going about this all wrong?
This is probably a newbie question but I am a little confused about how to go
next with my code. I think I want to use a factory pattern in this situation
but I am having trouble getting access to properties at the presentation
level. So my situation is I have a Vehicle base class.
Public Class Vehicle
Property BodyType as String
End Class
Then I have multiple inherited Classes
Public Class Truck inherits Vehicle
Property Weight as String
End Class
Public Class Forklift inherits Vehicle
Property EngineType as String
End Class
My factory uses a select statement on the Body Type to decide which class to
instantiate.
Public Class VehicleFactory
Public Shared Function CreateVehicleInstance(bodyType as String) as Vehicle
Select Case bodyType
Case "Truck"
return v as New Truck
Case "Forklift"
return v as New Forklift
End Select
return v
End Function
End Class
My problems comes when I try return my class from the factory and access
properties of the inherited class. The compiler won't let me compile it and I
am not sure where to go. So for exampl
Dim v as Vehicle = VehicleFactory.CreateVehicleInstance("Truck")
v.Weight = 6 'this give me a compile error that Weight is not a member of
the base class
I am trying to use this on the form and once the object is created then I
need it accesible to the form to track whether it needs to be saved back to
the database or not. Am I going about this all wrong?