I'm making a console calculator as a test project. Main feature of my realisation of it is that i made digits and operators classes inherited from ITerm interface:
public interface ITerm
{
Object Value { get; }
}
Now, i'm inheriting it in IOperand and IOperator interfaces and using these intefaces in further calculations via reverse poland notation.
And now, i've been told that using this Object-type property both to keep numbers and operators is violation of Single Responsibility Principle.
private ITerm CalculatePostfixExpression(IEnumerable<ITerm> input)
{
var tempResult = new Stack<ITerm>();
foreach (var term in input)
{
if (term is IOperand)
{
tempResult.Push(term as IOperand);
}
if (term is IOperator)
{
tempResult.Push(ProceedOperation(term as IOperator, tempResult));
}
}
return tempResult.Peek();
}
This is how i am handling calculation. So there are two questions: 1. Is there some defects in my idea about storing both operands and operators in Object variable? 2. Is there some ways to improve my code? I'm considering using visitor pattern in CalculatePostfixExpression method now.