i'm currently working on a little game and I have a question about OOP practices. My question is is there any way to access variables from child classes if you have a list or an array of objects which are of the parent type.
I'm currently in a CS course at school right now so I don't have my source code on me but it's been bugging me, I'm not quite sure what i'm supposed to be looking for here either, possibly a cast? my OOP knowledge is a little scattered (it's pretty hard to find good resources on OOP other than Stack Overflow, point me in the direction of a good tutorial if you know of one) but I want to implement good practices so I don't run into problems down the road (it's a rather large project)
Let me illustrate what I mean here (again I don't have my source on me, but it's something like this):
List<Tile> Tiles = new List<Tile>();
Tiles.add(new Water());
Tiles.add(new Sand());
foreach(Tile tile in Tiles)
{
tile.variable_fromsand = 10; //hypothetical, how could I access a public
//member from sand here, if at all
}
where water and sand are sub-classes of the base class Tile.
I'm sorry if this has been answered before, I'm not sure what it is that i'm looking for. Please point me to the correct thread if this has been answered adequately in the past.