public void ChangeStrategy(char @operator)
        {
            IStrategy currentStrategy = null;

            switch (@operator)
            {
            case '+':
                currentStrategy = new AdditionStrategy();
                break;

            case '-':
                currentStrategy = new SubtractionStrategy();
                break;

            case '*':
                currentStrategy = new MultiplicationStrategy();
                break;

            case '/':
                currentStrategy = new DivisionStrategy();
                break;
            }

            this.strategy = currentStrategy;
        }
Exemple #2
0
 public PrimitiveCalculator()
 {
     this.additionStrategy       = new AdditionStrategy();
     this.subtractionStrategy    = new SubtractionStrategy();
     this.multiplicationStrategy = new MultiplicationStrategy();
     this.divisionStrategy       = new DivisionStrategy();
     this.strategies             = new Strategy[] { this.additionStrategy, this.subtractionStrategy, this.multiplicationStrategy, this.divisionStrategy };
     this.currentStrategy        = this.additionStrategy;
 }