public IGumballMachineState GetSoldState() { if (_soldState == null) { _soldState = new SoldState(_gumballMachine, this); } return(_soldState); }
public IGumballMachineState GetHasCoinState() { if (_hasCoinState == null) { _hasCoinState = new HasCoinState(_gumballMachine, this); } return(_hasCoinState); }
public IGumballMachineState GetNoCoinState() { if (_noCoinState == null) { _noCoinState = new NoCoinState(_gumballMachine, this); } return(_noCoinState); }
public IGumballMachineState GetStartingState() { if (_startingState == null) { _startingState = new ErrorState(_gumballMachine, this, new Exception("Starting state undefined.")); } return(_startingState); }
public GumballMachine(int numGumballs) { _soldOutState = new OutOfGumballsState(this); _noQuarterState = new NoQuarterState(this); _hasQuarterState = new HasQuarterState(this); _soldState = new GumballSoldState(this); _winnerState = new GumballWinnerState(this); _gumballCount = numGumballs; _state = _gumballCount > 0 ? _noQuarterState : _soldOutState; }
public GumballMachine(int totalGumballs) { _soldOutState = new SoldOutState(this); _noQuarterState = new NoQuarterState(this); _hasQuarterState = new HasQuarterState(this); _soldState = new SoldState(this); _totalGumballs = totalGumballs; if (totalGumballs > 0) { _state = _noQuarterState; } else { _state = _soldOutState; } }
public void EjectCoin() { _state = _state.EjectCoin(); }
public void InsertCoin() { _state = _state.InsertCoin(); }
public void SetState(IGumballMachineState state) { _state = state; }
internal void SetState(IGumballMachineState state) { _state = state; }
public StateFactory(GumballMachine gumballMachine, IGumballMachineState startingState) { _gumballMachine = gumballMachine; _startingState = startingState; }
public IGumballMachineState GetErrorState(Exception e = null) { _errorState = new ErrorState(_gumballMachine, this, e); return(_errorState); }
public IGumballMachineState GetSoldOutState() { _soldOutState = new SoldOutState(_gumballMachine, this); return(_soldOutState); }
internal void SetNextState(IGumballMachineState nextState) { _nextState = nextState; }
public void TurnLever() { _state = _state.TurnLever(); }
private void LoadNextState() { _currentState = _stateFactory.GetNextState(); }
public StateFactory(GumballMachine gumballMachine) { _gumballMachine = gumballMachine; _startingState = new ErrorState(_gumballMachine, this, new Exception("Starting state undefined.")); }