Field definition for extending classes Question.
I'm not entirely sure how to describe my problem clearly, so please bear with me.
I've got a Galaxy Class.
Then I have 3 classes that extend Galaxy: Spiral, Elliptical and Barred.
Galaxy Class holds generic info like overall size, etc.
Each particular galaxy type generates the galaxy itself plus some more fields and methods that are only used in that type of galaxy.
Now, in my main class where everything goes, I have to define a variable that will hold the newly generated galaxy. Since everything is generated randomly, if I reference the new galaxy as Galaxy, it doesn't have the specific galaxy type's methods and fields.
And later if I try to use:
protected Galaxy galaxy;
it won't work because that's only in Elliptical galaxy.
So, I guess the question becomes: Do I make a variable for each type and only use the right one when it has been made clear which type of galaxy will be generated? If so I'll have to "if" or "switch" everything pertaining to galaxy argument passing, so I can use the right type of galaxy...
There's got to be an easier way.
Please help. :)