title: Review my design : Tic tac toe game using OO methodology
body: <p>This was asked as an interview question. </p>
  
  <p>Design a tic tac toe using object oriented principles. The interviewer said he is not interested in the logic and he wants only the design. I gave the design as below but I was not completely satisfied. Please let me know if there are any suggestions/improvements.</p>
  
  <p>The interviewer was very particular about two things </p>
  
  <ol>
  <li>The game can be played for n x n squares.</li>
  <li>The games rules should be separate from the rest of the application.</li>
  </ol>
  
  <p>My approach :</p>
  
  <ol>
  <li>Tic tac toe is a board game (Game object, Board object)</li>
  <li>Board consists of an Array of Squares (Square object)</li>
  <li>Squares can be marked as X or O.</li>
  <li>Two players play the game( Human and Computer classes implements Player interface)</li>
  <li>Once X or O is placed, the GameEngine (GameEngine object) decides if the game is 
    over(draw or the player won) or it's still on</li>
  <li>If the game is still on, the other player is given his turn.   </li>
  <li>For the Computer player , GameEngine figures out where to locate the next piece.</li>
  </ol>
  
  <p>Rough sketch of classes.</p>
  
  <pre><code> interface Player {
      Player takeTurn();
    void markNextBox();
    }
  </code></pre>
  
  <p>.</p>
  
  <pre><code> public class TicTacToeGameEngine implements GameRule{
  @Override
  public Boolean isWinner(Game game) {
          // Check winner logic
          return false;
  }
  
  @Override
  public Square locateSquareToMark(Game game) {
      List&lt;Square&gt; squares= game.getBoard().getFilledSquares();
      //go through the list of squares and figure out a square to mark
      return square;
      }
   }
  </code></pre>
  
  <p>.</p>
  
  <pre><code>  public class Computer implements Player {
  GameRule g = new TicTacToeGameEngine();
  @Override
  public void markNextBox() {
      g.locateSquareToMark(game);
  }
  @Override
  public Player takeTurn() {
      // TODO Auto-generated method stub
      return null;
  }
   }
  </code></pre>
  
  <p>.</p>
  
  <pre><code> public interface GameRule {
      Boolean isWinner(Game game);
      Square locateSquareToMark(Game game);
       }
  </code></pre>
  
  <p>//Similar implementation for Human</p>
  
  <p>Now the difficulties I found in this design is</p>
  
  <ol>
  <li>Does the Player need to know about the GameEngine ?</li>
  <li>How to pass on the control to the next player if the game is still on. (How to implement takeTurn() )</li>
  <li>I initially decided that the Game object should hold the state. If you look at the Computer class, I pass the game object to the GameEngine. Is it good to do it here? I feel something better can be done about it.</li>
  </ol>
  
  <p>Any flaws, improvements to design will be appreciated.</p>