CS 1713 Week 10:
A Design Example

Tic Tac Toe Tracing Rules

GameInterface
public boolean move(int row, int col);
public void startGame();
public char joinGame(UserInterface user);


UserInterface
public void setDone(char c);
public void requestMove();
public void setBoard(char[][] board);

Game Constructor:
public Game(int boardsize);

User Constructor:
public User(GameInterface game);
Tic Tac Toe Tracing Demonstration: One student is the Game (implements GameInterface)
Two students are Users, each implements UserInterface.

The driver program is run:

  public static void main(String[] args) {
    GameInterface game = new Game(3);
    new User(game);
    new User(game);
    game.startGame();
  }
Rules:
  1. Each object keeps track of its attributes on the whiteboard.
  2. We assume that only that object can see these attributes.
  3. All communication is done with a single pad which is passed among the objects.
  4. You call a method by writing the name of the method and the parameters on the pad, and giving the pad to the person simulating that object.
  5. You can only take action when you have the pad.
  6. When you receive the pad, tell the class what is on the pad. You may call any private methods, or public methods of objects you know about. Write the return value on the pad, if any and return the pad when you have completed the required action.
  7. When you receive the pad back, tell the class the return value, if any, and continue.