Ejemplo n.º 1
0
        public static IStrategy FindStrategy(char @operator)
        {
            IStrategy strategyToChange = null;

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

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

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

            case '/':
                strategyToChange = new DivisionStrategy();
                break;

            default:
                throw new ArgumentException($"Invalid operator {@operator} !");
            }

            return(strategyToChange);
        }
Ejemplo n.º 2
0
 public PrimitiveCalculator()
 {
     this.additionStrategy       = new AdditionStrategy();
     this.subtractionStrategy    = new SubtractionStrategy();
     this.multiplicationStrategy = new MultiplicationStrategy();
     this.divisionStrategy       = new DivisionStrategy();
     this.isAddition             = true;
 }