Example #1
0
        static void Main(string[] args)
        {
            // Setup context in a state
            Context c = new Context(new ConcreteStateA());

            //Issue request, which toggles state
            c.Request();
            c.Request();
            c.Request();
            c.Request();

            Console.ReadLine();
        }
        static void Main(string[] args)
        {
            Context context = new Context();

            //Usually a tree
            ArrayList list = new ArrayList();

            //Populate 'abstract syntax tree
            list.Add(new TerminalExpression());
            list.Add(new NonTerminalExpression());
            list.Add(new TerminalExpression());
            list.Add(new TerminalExpression());

            foreach (AbstractExpression exp in list)
            {
                exp.Interpret(context);
            }
            Console.ReadLine();
        }
 public abstract void Interpret(Context context);
 public override void Interpret(Context context)
 {
     Console.WriteLine("Called Terminal.Interpret()");
 }
Example #5
0
 public override void Handle(Context context)
 {
     context.State = new ConcreteStateB();
 }
Example #6
0
 public abstract void Handle(Context context);