Is there a way to use the New operator with a variable class name?
Consider the following class hierarchy:
- ---- Orange
- ---- Apple
- ---- Grape
- ---- etc…
Now, a random subclass of Fruit is created and stored in a Fruit variable.
In a method in the Fruit class, we need to make more of the same class. Something like this:
[code]function MakeAnotherFruitJustLikeThisOne(myFruit as Fruit)
dim newFruit as Fruit newFruit = New [i]<SubclassOf_myFruit>[/i] ...
And here is my problem. In the Fruit class, when I’m given a random Fruit object that will actually be some subclass of Fruit, I need to make more of the same object. Yes, I could have a switch statement that does a bunch of IsA and figures out which Fruit subclass I’ve actually been given, but I’m looking for a method that is more introspection based. I’d prefer the language to be able to figure this out without having to maintain a manual list of the possible subclasses in a big switch/IsA statement.