title: How to divide a method into sub-methods effectively?
body: <p>So basically what this thread boils down to is that I want some private methods to just represent a block of code inside another method. I'm aware of how scoping works in Java but there are times where I wish things worked differently:</p>
  
  <p>Suppose I have a method <em>doLotsOfStuff()</em> in my class that does more than one thing. Naturally one would divide the things into several methods <em>doThis()</em> and <em>doThat()</em> of type <em>VOID</em>. You encounter problems of this kind:</p>
  
  <p>1) I can no longer operate on any data defined in  <em>doLotsOfStuff()</em> in either <em>doThis()</em> and <em>doThat()</em> without first passing all the necessary arguments needed, which would not make them void! For example <em>doThis(int doLotsOfStuffsInt)</em> This means that if I want a chain of calls, the same <strong>variable must be passed</strong> along throughout in a line of arguments. ..which leads to this:</p>
  
  <p>2) <em>doThis()</em> and <em>doThat()</em> set as private would still be visible for all other methods in the same class, even though I just want to use them for <em>doLotsOfStuff()</em>. Having a long chain of sub methods that are only meant to be used a single time will now clutter up the whole Class.</p>
  
  <p>Here is what I wish existed: 
  a,b,c,d are private methods in the same class. The -> indicates a call to a method.</p>
  
  <p><strong>a() -> b() -> c()</strong>    </p>
  
  <p>c() can use variables from a() or b() freely without passing the arguments around down the chain.</p>
  
  <p><strong>d() -/-> c()</strong>        </p>
  
  <p>c() cannot be called by d() as c() is only "local" to a() and any of its subsequent callers. </p>
  
  <p>Consider the short example:</p>
  
  <pre><code>private void someMethod()
  {
      char a = 'a';
      printA();
  }
  
  
  private void printA() {
      System.out.println(a);  //a cannot resolve, but I don't want to pass it as an argument from someMethod()!
  }
  </code></pre>
  
  <p>Is there a way to achieve this, without having to pass a as an argument? Some sort of declaration in the lines of 
  "private void printA() dependson someMethod"? </p>
  
  <p>Wouldn't this be a good functionality to have? If not, why? How would you do it?</p>