How to implement polymorphism in inherited function's argument

K

kenneth.choe

(Any help would be very much appreciated.)

I have a base class QueryBase, to implement generalization.


MustInherit Class QueryBase
Public MustOverride Function GetData(ByVal dataSetType As
DataSetTypeBase) As DataSet
End Class

Enum DataSetTypeBase As Integer
IdentifierOnly = 1
FullSet = 2
End Enum


And, I have CustomerQuery, which inherits from QueryBase.


Class CustomerQuery
Inherits QueryBase

Public Overrides Function GetData(ByVal dataSetType As
DataSetTypeBase) As System.Data.DataSet

End Function

End Class

Public Enum CustomerDataSetType As Integer
IdentifierOnly = 1
FullSet = 2
FullSetWithPurchaseProfiling = 3 ' additional data set type
End Enum


As you can see, I want to add one more DataSetType on CustomerQuery.
Other inheriting queries may have their own data set type, too.

Now, I see Overrides does not let me use CustomerDataSetType instead
of DataSetTypeBase. Overrides requires exactly same signature and does
not allow widening or any.
I cannot make CustomerDataSetType to inherit from DataSetTypeBase
either, because it is not a class but just a enum, and you cannot
inherit enum. (I used Enum to have intellisense provide possible
values. I don't know if there is a way to do this with class.)

Do you have any suggestions how to implement this nicely?

Thank you.
 
F

Family Tree Mike

I think that if you created DataSetTypeBase and CustomerDataSetType as shared
classes with readonly properties for the individual query types, you might
get what you are after. CustomerDataSetType would add a property to the base
class for FullSetWithPurchaseProfiling.

I'm sure there are other approaches.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top