public GumballMachine(uint count, TextWriter textWriter) { _count = count; _textWriter = textWriter; _quarterCounter = new QuarterCounter(); _state = _count > 0 ? State.NoQuarter : State.SoldOut; }
public GumballMachineContext(uint numBalls, TextWriter textWriter) { _count = numBalls; _textWriter = textWriter; _soldOutState = new SoldOutState(this, _textWriter); _soldState = new SoldState(this, _textWriter); _noQuarterState = new NoQuarterState(this, _textWriter); _hasQuarterState = new HasQuarterState(this, _textWriter); QuarterCounter = new QuarterCounter(); _state = _count > 0 ? ( IState )_noQuarterState : _soldOutState; }