Implementation

There is nothing special about this implementation. We should simply overwrite the default constructor and assign a new instance to the ticTacToeCollection variable.

To begin with, we should add a local variable and a getter for TicTacToeCollection:

private TicTacToeCollection ticTacToeCollection;
 
protected TicTacToeCollection getTicTacToeCollection() {
  return ticTacToeCollection;
} 

Now all that's left is to instantiate a new collection and assign it to the variable when the main class is instantiated:

public TicTacToe() throws UnknownHostException {
  this(new TicTacToeCollection()); 
}
protected TicTacToe(TicTacToeCollection collection) {
  ticTacToeCollection = collection; 
} 

We also created another way to instantiate the class ...

Get Test-Driven Java Development - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.