Suppose I have a chessboard defined with a HashMap
HashMap <Position,Field> chessboard = new HashMap <Position,Field>();
I declare the Position
as
class Position{
int x;
int y;
}
When I am trying to make a class for Field
object I encounter a problem: the Field
should contain a Position
because it is defined by it. Ex.
class Field {
Position pos;
int color;
void draw(){
// draw Field using pos
}
}
But the Position object is going to be used for HashMap. How could I avoid this redundancy?