public double Calculate() { foreach (string part in splitCommand) { double number; if (Double.TryParse(part, out number)) { AddToStack(number); } else { IOperation operation = new OperationFactory().Create(part); double b = PopOffStack(); double a = PopOffStack(); AddToStack(operation.Calculate(a, b)); } } return(PopOffStack()); }