I am trying to create a class with a shared function that will return a class based on the value of a parameter, instead of a class instance (basically a class factory.) Then, I will call the class' constructor to get the instance I need.
For example, I have these three classes:
class Test
sub New(byval anID as Integer)
end sub
end class
class Test_A
inherits Test
sub New(byval anID as Integer)
end sub
end class
class Test_B
inherits Test
sub New(byval anID as Integer)
end sub
end class
I want something like (I know it does not work):
class TestFactory
shared function Create(byval aParam as Integer) as Test
select aParam
case 0
return Test_A
case 1
return Test_B
...
End Select
end function
end class
to later use it in the following way:
dim aTest as Test = New TestFactory.Create(0)(anID:=100)
I searched for similar question, and they all seem to suggest using generics. But in my case i think they are not suitable, since I need to know the class beforehand (see this answer.)
Any suggestions?