The problem
I have a generic base Interface A and Classes B anc C which derived from the generic Interface A but are no longer generic (A and B using different types) and I want to use class D that uses classes B and C (not in the same time) but class D needs to know the type of the generic they (classes B and C) using.
for example:
interface IA<T>
{
public T t;
//...
}
public B : IA <int> //...
public C : IA <string> //...
public D<T>
{
public IA<T> a;
public D(A a_) {a = a_}
//.. using a.t here(from classes B or C) .
}
The problem is that now that I want to create instance of D, I need to tell the constructor which type of T i'm using, and I would like that it would get it by itself from the type it get in the constructor (according to if it's type B or C).
I might have it all wrong and used the generic poorly, so please feel free to offer any other design.
Some background information
I'm trying to write a few agents (class D in the example) that will get any board game (interface IA in the example), learn it and play it all by themselves.
That's why I need some interface for the game, but each game has it's own "what on board" if it's int/double/string and also it's own way how to play a turn (tic-tac-toe (class B) is just the point on the board while chess (class C) needs 2 points- from and to), so the agents needs to know which kind of move he should return according to the dynamic game.
Aucun commentaire:
Enregistrer un commentaire