title: Object Oriented Design for a Chess game
body: <p>I am trying to get a feel of how to design and think in an Object Oriented manner and want to get some feedback from the community on this topic. The following is an example of a chess game that I wish to design in an OO manner. This is a very broad design and my focus at this stage is just to identify who is responsible for what messages and how the objects interact each other to simulate the game. Please point out if there are elements of bad design (high coupling, bad cohesion etc.) and how to improve on them. </p>
  
  <p>The Chess game has the following classes</p>
  
  <ul>
  <li>Board</li>
  <li>Player</li>
  <li>Piece</li>
  <li>Square</li>
  <li>ChessGame</li>
  </ul>
  
  <p>The Board is made up of squares and so Board can be made responsible for creating and managing Square objects. Each piece also is on a square so each piece also has a reference to the square it is on. (Does this make sense?). Each piece then is responsible to move itself from one square to another.
  Player class holds references to all pieces he owns and is also responsible for their creation (Should player create Pieces?) . Player has a method takeTurn which in turn calls a method movePiece which belongs to the piece Class which changes the location of the piece from its current location to another location. Now I am confused on what exactly the Board class must be responsible for. I assumed it was needed to determine the current state of the game and know when the game is over. But when a piece changes it's location how should the board get updated? should it maintain a seperate array of squares on which pieces exist and that gets updates as pieces move? </p>
  
  <p>Also, ChessGame intially creates the Board and player objects who in turn create squares and pieces respectively and start the simulation. Briefly, this might be what the code in ChessGame may look like</p>
  
  <pre><code>Player p1 =new Player();
  Player p2 = new Player();
  
  Board b = new Board();
  
  while(b.isGameOver())
  {
    p1.takeTurn(); // calls movePiece on the Piece object
    p2.takeTurn();
  
  }
  </code></pre>
  
  <p>I am unclear on how the state of the board will get updated. Should piece have a reference to board? Where should be the responsibility lie? Who holds what references? Please help me with your inputs and point out problems in this design. I am deliberately not focusing on any algorithms or further details of game play as I am only interested in the design aspect. I hope this community can provide valuable insights.  </p>