// Singleton public static BattleShipGame getInstance() { if (instance == null) { lock (syncRoot) // Is used in order to not to be ambiguity // during execution of different threads... { if (instance == null) { instance = new BattleShipGame(); } } } return(instance); }
// Singleton + Builder public static BattleShipGame getInstance(BattleShipPlayer _first, BattleShipPlayer _second) { if (instance == null) { lock (syncRoot) // Is used in order to not to be ambiguity // during execution of different threads... { if (instance == null) { player1 = _first; // player1 is of type BattleShipPlayer abstract class player2 = _second; // player2 is of type BattleShipPlayer abstract class instance = new BattleShipGame(); } } } return(instance); }
public void setToNull() { instance = null; }