title: Accessing parent class instance variables from child class instances
body: <p>So right now, I have a <code>Preprocessor</code> class that generates a bunch of instance variable maps, and a <code>Service</code> class that has a <code>setPreprocessor(Preprocessor x)</code> method, so that an instance of the <code>Service</code> class is able to access the maps that the preprocessor generated.</p>
  
  <p>At the moment, my <code>Service</code> class needs to call three methods in succession; for sake of simplicity, let's call them <code>executePhaseOne</code>, <code>executePhaseTwo</code>, and <code>executePhaseThree</code>. Each of these three methods instantiate/modify <code>Service</code> instance variables, some of which are pointers to the <code>Service</code> instance's <code>Preprocessor</code> object.</p>
  
  <p>My code has this structure right now:</p>
  
  <pre><code>Preprocessor preprocessor = new Preprocessor();
  preprocessor.preprocess();
  Service service = new Service();
  service.setPreprocessor(preprocessor);
  service.executePhaseOne();
  service.executePhaseTwo();
  service.executePhaseThree();
  </code></pre>
  
  <p>To better organize my code, I want to put each <code>executePhaseXXX()</code> call in its own separate subclass of <code>Service</code>, and leave the common data structures for all the phases in the parent class <code>Service</code>. Then, I want to have an <code>execute()</code> method in the <code>Service</code> parent class that executes all three phases in succession:</p>
  
  <pre><code>class ServiceChildOne extends Service {
      public void executePhaseOne() {
          // Do stuff
      }
  }
  
  class ServiceChildTwo extends Service {
      public void executePhaseTwo() {
          // Do stuff
      }
  }
  
  class ServiceChildThree extends Service {
      public void executePhaseThree() {
          // Do stuff
      }
  }
  </code></pre>
  
  <p>EDIT:</p>
  
  <p>The problem is, how do I write my <code>execute()</code> method in the <code>Service</code> parent class? I have:</p>
  
  <pre><code>public void execute() {
      ServiceChildOne childOne = new ServiceChildOne();
      ServiceChildTwo childTwo = new ServiceChildTwo();
      ServiceChildThree childThree = new ServiceChildThree();
      System.out.println(childOne.preprocessor); // prints null
      childOne.executePhaseOne();
      childOne.executePhaseTwo();
      childOne.executePhaseThree();
  }
  </code></pre>
  
  <p>However, my <code>childOne</code>, <code>childTwo</code>, and <code>childThree</code> objects aren't able to access the <code>preprocessor</code> instance variable that lives in the parent class <code>Service</code>... How could I get past this problem?</p>