title: Is it preferable to pass the whole object or call a method on it and pass the returned value?
body: <p>I am providing the examples below to further illustrate my point:</p>
  
  <p>Example 1:</p>
  
  <pre class="lang-java prettyprint-override"><code>public class A {
  
      public String getTheNeededString() {
          String returnedString;        
          //logic goes here
          return returnedString;    
      }
  }
  
  public class B {
      public void doSomething(A objectA) {
          String neededString = objectA.getTheNeededString();
          //proceed to do something that needs the above String
      }
  }
  
  public class Client { 
      public static void main(String[] args) {
          A objectA = new A();
          B objectB = new B();
          objectB.doSomething(objectA);
      }
  }
  </code></pre>
  
  <p>Example2:</p>
  
  <pre class="lang-java prettyprint-override"><code>public class A {
      //stays the same
  }
  
  public class B {
     public void doSomething(String neededString) {
         //proceed to do something that needs the above String
     }
  }
  
  public class Client { 
      public static void main(String[] args) {
          A objectA = new A();
          String neededString = objectA.getTheNeededString();
          B objectB = new B();
          objectB.doSomething(neededString);
      }
  }
  </code></pre>
  
  <p>I guess that there might not be a "better" approach and it might be a matter of preference.
  If that's the case, then I would really appreciate any opinion/preference on the matter.</p>