Use the design mode to solidify your C # Program (5-1)
Design Patterns: Solidify Your C # Application Architecture with Design Patterns Chinese edition (Part 1)
Author: Samir Bajaj
Translator: glory
[Translation: C # advanced article. The translator simply sorts out the C # examples provided by Samir (some of the Code provided by the author cannot be compiled in the translator's environment) and compiles the corresponding C ++ example, put them in comments for readers to compare. All C # And C ++ debugging environments are Microsoft Visual Studio. NET 7.0 Beta2]
Some code:
C # example:
Using System;
Abstract class State
{
Public virtual void AddNickel (VendingMachine vm ){}
Public virtual void AddDime (VendingMachine vm ){}
Public virtual void AddQuarter (VendingMachine vm ){}
Protected virtual void ChangeState (VendingMachine vm, State s)
{
Vm. ChangeState (s );
}
}
......
/* The following is the output result of a running task:
The Vending Machine is now online: product costs 25c
Credit: 0c
Insert a coin <5, 10, 25>: 5
Credit: 5c
Insert a coin <5, 10, 25>: 10
Credit: 15c
Insert a coin <5, 10, 25>: 5
Credit: 20c
Insert a coin <5, 10, 25>: 5
Dispensing product... Thank you!
*/