Ok, So I have the following situation. I originally had some code like this:
public class MainBoard {
private BoardType1 bt1;
private BoardType2 bt2;
private BoardType3 bt3;
...
private readonly Size boardSize;
public MainBoard(Size boardSize) {
this.boardSize = boardSize;
bt1 = new BoardType1(boardSize);
bt2 = new BoardType2(boardSize);
bt3 = new BoardType3(boardSize);
}
}
Now, I decided to refactor that code so the classes' dependencies are injected, instead:
public class MainBoard {
private IBoardType1 bt1;
private IBoardType2 bt2;
private IBoardType3 bt3;
...
private Size boardSize;
public MainBoard(Size boardSize, IBoardType1 bt1, IBoardType2 bt2, IBoardType3 bt3) {
this.bt1 = bt1;
this.bt2 = bt2;
this.bt3 = bt3;
}
}
My question is what to do about Board Size? I mean, in the first case, I just passed the class the desired board size, and it would do everything to create the other kinds of boards with the correct size. In the dependency injection case, that might not be more the case. What do you guys do in this situation? Do you put any kind of checking on the MainBoard
's constructor so to make sure that the correct sizes are being passed in? Do you just assume the class' client will be responsible enough to pass the 3 kinds of boards with the same size, so there is no trouble?
Edit
Why am I doing this? Because I need to Unit-Test MainBoard. I need to be able to set the 3 sub-boards in certain states so I can test that my MainBoard is doing what I expect it to.
Thanks