public GumballMachineContext(uint numBalls) { _soldState = new SoldState(this); _soldOutState = new SoldOutState(this); _noQuarterState = new NoQuarterState(this); _hasQuaterState = new HasQuaterState(this); _count = numBalls; _state = (_count > 0) ? _noQuarterState : (IState)_soldOutState; }
public GumballMachine(int totalBalls) { SoldOutState = new SoldOutState(this); SoldState = new SoldState(this); NoQuarterState = new NoQuarterState(this); HasQuarterState = new HasQuarterState(this); Count = totalBalls; CurrentState = Count > 0 ? NoQuarterState : SoldOutState; }
public GumballMachine(int numberOfGumballs) { SoldOutState = new SoldOutState(this); NoQuarterState = new NoQuarterState(this); HasQuarterState = new HasQuarterState(this); SoldState = new SoldState(this); Count = numberOfGumballs; if (numberOfGumballs > 0) { State = NoQuarterState; } else { State = SoldOutState; } }