Exemple #1
0
		static void Main(string[] args)
		{
            CalculatorFullBridgeWithState proc = new CalculatorFullBridgeWithState();
            proc.op = CalculatorFullBridgeWithState.Ops.Add;
            proc.doIt( 2);
            proc.doIt( 3);
            proc.doIt( 4);
            proc.op = CalculatorFullBridgeWithState.Ops.Subtract;;
            proc.doIt( 7);
            proc.op = CalculatorFullBridgeWithState.Ops.Recall;
            proc.doIt( 0);
		}
        public int process(int runningTotal, int value)
        {
            CalculatorFullBridgeWithState proc = new CalculatorFullBridgeWithState();
            MyRecall recall = new MyRecall();

            foreach (Step item in _list)
            {
                if (item._op == CalculatorFullBridgeWithState.Ops.Recall)
                {
                    // This is why plugins are SO IMPORTANT...
                    // We have a hack because the abstract factory is hard coded,
                    // meaning we have to update the abstract factory or the state class
                    // It is partially ok to update the factory or state, because it is a single change.
                    // However, if this
                    // were implemented with configuration files, then only the configuration
                    // file would need changing.  If you do not want to use the plugin
                    // architecture then ALWAYS have a safe back door in the state pattern
                    proc.useCustomOperation(recall);
                }
                else
                {
                    proc.op = item._op;
                }
                proc.doIt(item._val);
            }
            return(recall._runningTotal);
        }
        static void Main(string[] args)
        {
            CalculatorFullBridgeWithState proc = new CalculatorFullBridgeWithState();

            proc.op = CalculatorFullBridgeWithState.Ops.Add;
            proc.doIt(2);
            proc.doIt(3);
            proc.doIt(4);
            proc.op = CalculatorFullBridgeWithState.Ops.Subtract;;
            proc.doIt(7);
            proc.useCustomOperation(new FormulaToOperationsAdaptor());
            proc.doIt(4);
            proc.op = CalculatorFullBridgeWithState.Ops.Recall;
            proc.doIt(0);
        }