What I want to do:
abstract class TileBase
{
protected TileGroup<TileBase> tileGroup;
}
class Tile : TileBase
{
public Tile(Province Province)
{
tileGroup = Province;
}
}
abstract class TileGroup<T>
{
protected T[] tiles;
protected TileGroup<TileGroup<T>> tileGroup;
}
class Province : TileGroup<TileBase>
{
public Province(Tile tile, Nation nation)
{
tiles = new[] { tile };
tileGroup = nation;
}
}
class Nation : TileGroup<Province>
{
public Nation(Province province)
{
tiles = new[] { province };
tileGroup = null;
}
}
This will not work because of invariance (if I understand invariance correctly): cannot convert Nation to TileGroup<TileGroup<TileBase>>
So I'll need to write it like this:
class Nation : TileGroup<TileGroup<TileBase>>
{
public Nation(Province province)
{
tiles = new[] { province };
tileGroup = null;
}
}
But when layers get stacked; this gets ugly fast:
Map : TileGroup<TileGroup<TileGroup<TileBase>>>
This also makes adding layers between two existing layers difficult because one change in a low layer means changing all the higher layers.
So how exactly should I be doing this?
Sorry for the formulation, I know what I want, but not how I should explain it clearer than in this way.