Use this simple example:
Connect4Board.cs:
public class Connect4Board { private Box[,] _boxes = new Box[7, 6]; public void DropPieceAt(int column, bool redPiece) {
Box.cs :
public class Box { public bool IsRed { get; private set; } public bool IsEmpty { get; private set; } }
I want GetBoxAt() return a field with read-only properties. However, I want my Connect4Board be able to change the colors of the boxes.
Suppose I don’t want to use the internal modifier at all.
My solution (pretty ugly):
public class Connect4Board { private Box.MutableBox[,] _mutableBoxes = new Box.MutableBox[7, 6]; public Connect4Board() { for (int y = 0; y < 6; y++) { for (int x = 0; x < 7; x++) { _mutableBoxes[x, y] = new Box.MutableBox(); } } } public void DropPieceAt(int column, bool isRed) {
Is there any good design to make it more elegant?
source share