private static void Main(string[] args) { var stateA = new ConcreteStateA(); var context = new Context(stateA); context.Request1(); context.Request1(); Console.WriteLine("Hello World!"); }
static public void Main() { State stateA = new ConcreteStateA(); State stateB = new ConcreteStateB(); Context context = new Context(stateA); context.Request(); //表现状态A的行为 context.SwitchSate(stateB); context.Request(); //表现状态B的行为 }