C
Chet Cromer
I am creating a set of base classes and sub classes to use throughout a
program I'm developing. The base class represents a generic "lookup
table" from my database that contains lists of things like
manufacturers, makes, modes, etc. of cars. I have created a generic
"datacollection" class and a generic "dataobject" class to represent the
table and the rows within that table as a collection of objects with
generic properties for manipulating fields, adding rows, etc.
The problem I'm having is that I have a generic "Item" method in the
DataCollection class that takes a key parameter and then looks it up in
the data table and returns the information as a "DataObject" class. I
have then written subclasses to more specifically use the base class for
a particular type of data (in the example I'm providing, a vehicle
manufacturer). So I now have a "Manufacturers" object that inherits from
DataCollection and a "Manufacturer" object that inherits from
DataObject. So, back to my problem. In the item method, the generic
DataCollection class requires a "Key" that will be used for the lookup.
It then searches its internal data table and returns the appropriate
DataObject object. However, what I WANT, is to create an overriding Item
object in my Manufacturers object that returns a MANUFACTURER instead of
a DATAOBJECT. So I created a Public Shadows property that returns a
Manufacturer object but callse the MyBase.Item function to get it. But
MyBase.Item returns a DataObject, not a objManufactuer, and then I get
thrown my Invalid Cast Exception.
I hope that explains my predicament. Can anyone help? Here is the basics
of my code:
Public Class objDataCollection
Public Readonly Property Item (byval Key as Object) as
objDataObject
Get
...
Return new objDataObject(...)
End Get
End Property
End Class
Public Class objDataObject
..
End Class
Public Class objManufacturers
Inherits objDataCollection
Public Shadows Readonly Property Item(byval Code as String)
as objManufacturer
Get
return MyBase.Item(code)
End Get
End Property
End Class
Public Class objManufacturer
Inherits objDataObject
..
End Class
program I'm developing. The base class represents a generic "lookup
table" from my database that contains lists of things like
manufacturers, makes, modes, etc. of cars. I have created a generic
"datacollection" class and a generic "dataobject" class to represent the
table and the rows within that table as a collection of objects with
generic properties for manipulating fields, adding rows, etc.
The problem I'm having is that I have a generic "Item" method in the
DataCollection class that takes a key parameter and then looks it up in
the data table and returns the information as a "DataObject" class. I
have then written subclasses to more specifically use the base class for
a particular type of data (in the example I'm providing, a vehicle
manufacturer). So I now have a "Manufacturers" object that inherits from
DataCollection and a "Manufacturer" object that inherits from
DataObject. So, back to my problem. In the item method, the generic
DataCollection class requires a "Key" that will be used for the lookup.
It then searches its internal data table and returns the appropriate
DataObject object. However, what I WANT, is to create an overriding Item
object in my Manufacturers object that returns a MANUFACTURER instead of
a DATAOBJECT. So I created a Public Shadows property that returns a
Manufacturer object but callse the MyBase.Item function to get it. But
MyBase.Item returns a DataObject, not a objManufactuer, and then I get
thrown my Invalid Cast Exception.
I hope that explains my predicament. Can anyone help? Here is the basics
of my code:
Public Class objDataCollection
Public Readonly Property Item (byval Key as Object) as
objDataObject
Get
...
Return new objDataObject(...)
End Get
End Property
End Class
Public Class objDataObject
..
End Class
Public Class objManufacturers
Inherits objDataCollection
Public Shadows Readonly Property Item(byval Code as String)
as objManufacturer
Get
return MyBase.Item(code)
End Get
End Property
End Class
Public Class objManufacturer
Inherits objDataObject
..
End Class