title: Java: Should occasionally used objects be included as a class member?
body: <p>I have a class <code>CodeText</code> as below:</p>
  
  <pre><code>public class CodeText{
      private char type;
      private int textCode;
      //Other members
  }
  </code></pre>
  
  <p>Occasionally, if there is an error when a <code>Symbol</code> object refers to a <code>CodeText</code> object, I need to "record" that <code>Symbol</code> so that the <code>CodeText</code> "knows" who is referring it when error happens.</p>
  
  <p>Currently I added another member "relatedSymbol" into class <code>CodeText</code> like below, but it feels like an ugly design. </p>
  
  <pre><code>public class CodeText{
      private char type;
      private int textCode;
      private Symbol relatedSymbol;
      //Other members
  }
  </code></pre>
  
  <p>I'm not sure if the above can be improved. Any suggestions are appreciated.</p>
  
  <p>Edit: Sorry that I didn't provide enough background information.
  My goal is as below:
  For class <code>CodeText</code>, the <code>textCode</code> value is adjusted depending on the type.
  E.g. if type is 'I'(meaning immediate), then <code>textCode</code> is unchanged;
  if type is 'E'(meaning external), then <code>textCode</code> should be recomputed and then refer to the address of an external <code>Symbol</code>.</p>
  
  <p>But occasionally, the value of <code>textCode</code> might be wrong. For example, if type is "E" but the value of <code>textCode</code> points
  to an illegal <code>Symbol</code>, then this error should be recorded and <code>CodeText</code> object should "know" which <code>Symbol</code> it tries to refer.</p>