Respect Encapsulation!

Don't write your classes like this example. The get and set methods completely expose the private instance variable "grid". This allows a client module to do anything they want with the grid, which defeats the entire purpose of encapsulating it in a class. In essence, you have just made grid a global variable.

The addItem() and isEmpty() methods are fine, assuming they perform appropriate data validity checking on the parameters.



/** * The Board class models the two dimensional gameboard. */ public class Board { private Item[][] grid; public Board() { (body omitted) } public void addItem(Item itemToAdd, Point position) { (body omitted) } public boolean isEmpty(Point currentPosition, Point nextPos, Point nextNextPos) { (body omitted) } public Item[][] getGrid() { return grid; } public void setGrid(Item[][] aGrid) { grid = aGrid; } }