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; } }