Note that there are some explanatory texts on larger screens.

plurals
  1. POType-safe way to store two types of object in a collection
    primarykey
    data
    text
    <p>I've been implementing an enhanced Shunting-Yard algorithm for parsing an arithmetic expression. One aspect of the algorithm, is that it maintains a <code>Queue</code>, and a <code>Stack</code>.</p> <p>In my implementation, the <code>Queue</code> contains <code>Expressions</code> and <code>Operators</code>. The <code>Stack</code> contains <code>Operators</code> and <code>Parenthesis</code>.</p> <p><code>Expressions</code>, <code>Parenthesis</code>, and <code>Operators</code> have nothing in common that warrants any two of them having a shared interface.</p> <p><strong>Approaches:</strong></p> <ul> <li><p>My current implementation consists of <code>Expression</code> and <code>Operator</code> implementing a <code>INotParanthesis</code>. <code>Operator</code> and <code>Paranthesis</code> implement a <code>INotExpression</code>. I then declare <code>Queue &lt;INotParanthesis&gt;</code>, and <code>Stack &lt;INotExpression&gt;</code>.</p> <p>I don't like this implementation - these interfaces seem very much a hack for the purpose of cleaner algorithm code. I also believe that interfaces should describe what an object is, as opposed to what it isn't.</p></li> <li><p>On the other hand, I also don't want to use collections of <code>&lt;Object&gt;</code>, as it can be difficult to be certain of the correctness of such code.</p></li> <li><p>The only one I've come up with, so far, is implementing my own <code>NonParanthesisQueue</code> and <code>NonExpressionStack</code> containers. This has the advantage of more consistent type checking on objects getting pulled out of those containers - and the disadvantage of a lot more code.</p></li> </ul> <p>Are there any reasonable alternatives to my approaches? </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload