public BinocularOperatorContext(string operaotrStr) { dictionary = new Dictionary <string, IBinocularOperator>(); dictionary.Add("+", new Add()); dictionary.Add("-", new Subtractcs()); dictionary.Add("*", new Multiply()); dictionary.Add("/", new Divide()); if (dictionary.TryGetValue(operaotrStr, out IBinocularOperator tempOperator)) { @operator = tempOperator; } }
public BinocularOperatorContextBySwitch(string operaotrStr) { switch (operaotrStr) { case "+": @operator = new Add(); break; case "-": @operator = new Subtractcs(); break; case "*": @operator = new Multiply(); break; case "/": @operator = new Divide(); break; } }