I often see people say things like "if you need friend/internal then your design is wrong", could someone tell me how to redesign the following code to eliminate the internal in ChessPiece.Location?
It's currently used so that adding a piece to ChessBoard sets the ChessPiece.Location property to match, obviously making it public would be even worse than internal and making it private would prevent ChessBoard from updating the Location. Thanks for any insights.
public struct Coord
{
public Coord(int x, int y) { this.X = x; this.Y = y; }
public int X { get; private set; }
public int Y { get; private set; }
}
public class ChessBoard
{
public ChessBoard() { /*[...]*/ }
public ChessPiece this[int x, int y]
{
get
{
// Return ChessPiece at this position (or null)
}
set
{
// Add ChessPiece at this position and set its Location property
}
}
public class ChessPiece
{
public ChessPiece() { /*[...]*/ }
public Coord Location { get; internal set; }
}