I have defined the following interface:
public interface IStateSpace<State, Action>
where State : IState
where Action : IAction<State, Action> // <-- this is the line that bothers me
{
void SetValueAt(State state, Action action);
Action GetValueAt(State state);
}
Basically, an IStateSpace
interface should be something like a chess board, and in each position of the chess board you have a set of possible movements to do. Those movements here are called IAction
s. I have defined this interface this way so I can accommodate for different implementations: I can then define concrete classes that implement 2D matrix, 3D matrix, graphs, etc.
public interface IAction<State, Action> {
IStateSpace<State, Action> StateSpace { get; }
}
An IAction
, would be to move up(this is, if in (2, 2)
move to (2, 1)
), move down, etc.
Now, I'll want that each action has access to a StateSpace so it can do some checking logic. Is this implementation correct? Or is this a bad case of a circular dependence? If yes, how to accomplish "the same" in a different way?
Thanks