GetType and typeof
<pre><code>Type typeThing = gumballMachine.GetState().GetType();
if (typeThing == typeof(NoQuarterState)) { ... }


IState state;
public IState GetState() {
    return state;
}


public class NoQuarterState : IState { ... }
</code></pre>

<p>I'm using a gumballMachine app from Ch10 of Head First Design Patterns.  <a href="http://www.programgood.net/2011/11/28/StateMachineAndGumballConsoleWinFormTests.aspx" rel="nofollow">full code here</a> This works.</p>

<p>Problem:  typeThing above smells!  Is there a better way? </p>
