title: OOP: Object Inheritance and Composition Relationships in Simple Game Design
body: <p>I'm currently learning Java for several reasons, but one of the main ones being that it's a very OOP orientated language, and writing code in Java is really helping me understand the core concepts behind OOP programming. </p>
  
  <p>I am, however, having difficulty in defining the relationships between my classes. I understand the difference between inheritance and composition, but I'm having some difficulty seeing the whole picture, and how all of my classes should work together as a whole.</p>
  
  <p>An example of how I would write a simple game of Tic-Tac Toe using OOP;</p>
  
  <ol>
  <li><p>Create a <code>Game</code> class - creates an instance of the <code>gameBoard</code> class,
  decides who starts first, keeps track of games won and lost, starts
  and ends the game.</p></li>
  <li><p>Create a <code>gameBoard</code> class - updates the tic-tac-toe board,
  determines the next player's turn, if a move is legal, and
  determines when there is a winner</p></li>
  <li><p>Create an abstract <code>Player</code> class - holds the player's tile (X or O), and
  contains a method that takes a <code>gameBoard</code> instance as an argument and
  passes the move made by the player to the instance reference</p></li>
  <li><p>Create a <code>Human</code> class that extends the <code>Player</code> class. Contains
  methods dealing with player input from the keyboard </p></li>
  <li><p>Create a <code>Computer</code> class that extends the <code>Player</code> class. Has a
  method that takes a <code>gameBoard</code> instance as an argument and analyses
  the gameboard for a winning move, a blocking move, or any other
  move, then makes a move</p></li>
  </ol>
  
  <p>This is the approach I would take. However, I'm having a little trouble relating all of the classes together. The line seems a little blurred in some cases as to where some methods and fields should belong.</p>
  
  <p><strong>Edit:</strong> Revised question:</p>
  
  <p>What would be a good methodology in determining clear, defined roles for my classes, without getting too caught up in trying to define and ecapsulate every aspect of my program? A lot of my objects could be called from other classes to perform the specific functions that each class has, i.e <code>Player</code> updates <code>gameBoard</code>, <code>gameBoard</code> updates <code>Game</code>, but I do not know if this is good practice, or will make for rigid and hard to maintain code by passing around too many object references.</p>