M
Mitch
Hi.
My problem is quite specific, but doing a search on inheritence was
just too much to sift through.
This post IS very long, and I am sorry, but I've gone for clarity
rather than brevity
I'll try to explain my specific problem in detail, though I expect the
answer is quite simple and common, for that I apologise.
I am writing a rail simulation piece, with each segment of rail an
object. I am then extending the railSection class to have more
specialised railSection objects, such as Signal and Point (to Americans
i think they are called intersections or junctions)...
Now if i have a 'train' running along the track (which is currently an
array or map (prob array) of railSections, how will i test to see if
say a signal is red?
I have a line which currently reads:
///////
while(this.currentRailSection.whatIsSignal() == signalState.RED)
this.currentRailSection.redSignal.await();
////////
Now obviously the 'currentRailSection' could be an extended Signal
railSection or just a standard railSection, and as the compiler see's
it as a standard railSection it flags a message.
Now if the Signal class inherited the 'signalState' from the
railSection i imagine all would be fine, however that is not how i
would like it to be. So i guess my question is how do I test for
something in an extended class when i have to refer to it as the base
class...?
I think an abstraction:
////////
class a
{
blah
}
class b extends a
{
blah...
private variable whatIsMyVariable() { return _variable; }
private variable _variable;
}
-=-=-=-=-=-=-
Now i want to do
while(a<100; a++)
IF(a.whatIsMyVariable == 123)
do something;
Knowing that it will return false whenever the class a ISN'T actually
b..
////////
So i would have an array which would be my route which would go
something like
railSection
railSection
railSection
railSection
Signal extends railSection
railSection
railSection
railSection
And prior to carrying onto the next railSection i want to test to see
if my signal is red.
Hope I have made myself clear and thank you to all who take the time to
read it, I know it's a beast.
Kind Regards,
Mitch.
My problem is quite specific, but doing a search on inheritence was
just too much to sift through.
This post IS very long, and I am sorry, but I've gone for clarity
rather than brevity
I'll try to explain my specific problem in detail, though I expect the
answer is quite simple and common, for that I apologise.
I am writing a rail simulation piece, with each segment of rail an
object. I am then extending the railSection class to have more
specialised railSection objects, such as Signal and Point (to Americans
i think they are called intersections or junctions)...
Now if i have a 'train' running along the track (which is currently an
array or map (prob array) of railSections, how will i test to see if
say a signal is red?
I have a line which currently reads:
///////
while(this.currentRailSection.whatIsSignal() == signalState.RED)
this.currentRailSection.redSignal.await();
////////
Now obviously the 'currentRailSection' could be an extended Signal
railSection or just a standard railSection, and as the compiler see's
it as a standard railSection it flags a message.
Now if the Signal class inherited the 'signalState' from the
railSection i imagine all would be fine, however that is not how i
would like it to be. So i guess my question is how do I test for
something in an extended class when i have to refer to it as the base
class...?
I think an abstraction:
////////
class a
{
blah
}
class b extends a
{
blah...
private variable whatIsMyVariable() { return _variable; }
private variable _variable;
}
-=-=-=-=-=-=-
Now i want to do
while(a<100; a++)
IF(a.whatIsMyVariable == 123)
do something;
Knowing that it will return false whenever the class a ISN'T actually
b..
////////
So i would have an array which would be my route which would go
something like
railSection
railSection
railSection
railSection
Signal extends railSection
railSection
railSection
railSection
And prior to carrying onto the next railSection i want to test to see
if my signal is red.
Hope I have made myself clear and thank you to all who take the time to
read it, I know it's a beast.
Kind Regards,
Mitch.