static void Main(string[] args) { VendingMachine vm = new VendingMachine(); vm.AddNickel(); vm.AddDime(); vm.AddNickel(); vm.AddDime(); }
public override void AddQuarter(VendingMachine vm) { vm.Vend(); vm.ChangeState(Start.Instance()); }
protected virtual void ChangeState(VendingMachine vm, State s) { vm.ChangeState(s); }
public override void AddNickel(VendingMachine vm) { this.ChangeState(vm,Twenty.Instance()); }
public virtual void AddNickel(VendingMachine vm) { }
public virtual void AddQuarter(VendingMachine vm) { }
public override void AddQuarter(VendingMachine vm) { vm.Vend(); // start over }
public virtual void AddDime(VendingMachine vm) { }
public override void AddDime(VendingMachine vm) { ChangeState(vm, Ten.Instance()); }
public override void AddNickel(VendingMachine vm) { ChangeState(vm, Five.Instance()); }
public override void AddQuarter(VendingMachine vm) { vm.Vend(); ChangeState(vm, Start.Instance()); // no change returned :-) }