title: Inheritance hierarchy for number system classes
body: <p>For symbolic representation of mathematical expressions, I am trying to build a hierarchy of number system classes.</p>
  
  <p>In addition to <code>Integer</code> and <code>Real</code>, I also need classes like <code>Rational</code> and <code>Complex</code>. I want all of these classes to inter-operate seamlessly with each other.</p>
  
  <p>e.g. Adding a <code>Complex</code> number to an <code>Integer</code> would give a <code>Complex</code> number etc.</p>
  
  <hr>
  
  <p>I made all of them to implement the <code>Number</code> interface. (NOT <code>java.lang.Number</code>)</p>
  
  <p>For being able to add numbers of different types, I tried making hierarchy like following.</p>
  
  <blockquote>
    <p><code>Integer</code> extends <code>Rational</code> extends <code>Real</code> extends <code>Complex</code></p>
  </blockquote>
  
  <ul>
  <li>This makes an <code>Integer</code> to unnecessarily store imaginary part etc. This overhead is undesired.</li>
  <li>Also allowing access to imaginary part of an <code>Integer</code> seems improper.</li>
  </ul>
  
  <hr>
  
  <p>Can anyone suggest a better design where overhead is avoided and interoperation is still possible?</p>