Originally posted by Jigar Gosarr:
Possiblity 1 nly chessboard has two dimentional array and stores reference to chesspiece in it and null value if there is no chesspiece present on that particular chess square(ie. arr[i][j]).
1.disadvantage:A lot of space will be wasted since there will be many null values.
3.disadvantage:it will be very difficult and time consuming process to query that given a chesspiece object, where it lies on chess board.We will have iterate all chess squares inquring wheather that i,j square contains the given chesspiece.
Possiblity 2 nly each chesspiece contains the info as to where it belongs on chessboard. this info is maintained in its private variable "int x,y".
1.disadvantage:it is possible that two chesspiece might ,by mistake, contain same x,y values this leads to inconsistancy since no two chesspiece can be on same chess square.
3.disadvantage:in order to find which chesspiece is present on given i,j square we will have to query all chesspiece and ask them wheather they are currently belonging to i,j square this is time consuming since there are 10000 chesspiece in this imaginary chess board.