Esempio n. 1
0
        public static void Main(string[] args)
        {
            // Client 端程式只須認識 StateContext, 不須認識 State 的父類別與實作
            StateContext context = new StateContext();

            for (int i = 0; i < 10; i++)
            {
                context.Request();
            }
            Console.ReadLine();
        }
 // 子類別須實作出特定狀態的具體行為內容
 public override void Handle(StateContext context)
 {
     Console.WriteLine("1");
     context.Current = new State2();
 }