示例#1
0
 public PrimitiveCalculator(AdditionStrategy additionStrategy, SubtractionStrategy subtractionStrategy,
                            MultiplyStrategy multiplyStrategy, DivideStrategy divideStrategy)
 {
     this.additionStrategy    = additionStrategy;
     this.subtractionStrategy = subtractionStrategy;
     this.multiplyStrategy    = multiplyStrategy;
     this.divideStrategy      = divideStrategy;
     this.additionValue       = additionStrategy;
 }
示例#2
0
    public void ChangeStrategy(char @operator)
    {
        switch (@operator)
        {
        case '+':
            this.additionValue = this.additionStrategy;
            break;

        case '-':
            this.additionValue = this.subtractionStrategy;
            break;

        case '*':
            this.additionValue = this.multiplyStrategy;
            break;

        case '/':
            this.additionValue = this.divideStrategy;
            break;
        }
    }