private Expression HandleExpressionWithOperation(string expression) { Expression exp = new ValueExpression(0); var characters = expression.ToCharArray(); for (var i = 0; i < characters.Length; i++) { var exp1 = expression.Substring(0, i); var exp2 = expression.Substring(i + 1); switch (characters[i]) { case '+': exp = new AddExpression(ChangeStrToExpression(exp1), ChangeStrToExpression(exp2)); break; case '-': exp = new SubtractionExpression(ChangeStrToExpression(exp1), ChangeStrToExpression(exp2)); break; default: break; } } return(exp); }
private static void CalculateWithoutEncapulate() { //10+5=15 Expression addExpression = new AddExpression(new ValueExpression(10), new ValueExpression(5)); //15-8=7 Expression subExpression = new SubtractionExpression(addExpression, new ValueExpression(8)); //15+7=22 addExpression = new AddExpression(addExpression, subExpression); Console.WriteLine(addExpression.Interpreter()); }