Game game = new Game();
game.moveO();
game.moveO();
game.moveO();
class Game{
Game(Player playerX, Player playerO);
move();
...
}
void moveX(){
if(currentPlayer != Player.X){
throw new NotTheTurnOfThePlayerException();
}
}
Eliminate Exceptions
class Game{
Game(Player playerX,
Player playerO);
move();
...
}
Pass Mandatory Arguments In Constructor
Game game =
new Game(firstPlayer,
secondPlayer);
game.addPlayer(thirdPlayer);
game.addPlayer(fourthPlayer);
game.move();
Avoid Primitive Obsession
game.move("A1");
game.move(0, 0);
Place place =
new Place(Coordinate.One,
Coordinate.One);
game.move(place);