title: Why do we pass objects rather than object members to functions?
body: <p>I have a method <code>FOO()</code> in class <code>A</code> that takes as its arguments input from data members of class <code>B</code> among other things (let's say they are two floats and one int). The way I understand this, it is generally better to implement this with something like:</p>
  
  <pre><code>A-&gt;FOO1(B, other_data_x)
  </code></pre>
  
  <p>rather than</p>
  
  <pre><code>A-&gt;FOO2(B.member1, B.member2, B.member3, other_data_x).
  </code></pre>
  
  <p>I gather one, but not the only, advantage of this is that it leaves the detail of which members of <code>B</code> to access up to <code>FOO1()</code> and so helps hide implementation details.</p>
  
  <p>But what I wonder about is whether this actually introduces additional coupling between classes <code>A</code> and <code>B</code>. Class <code>A</code> in the former case has to know class <code>B</code> exists (via something like <code>include class_B_header.h</code>), and if the members of <code>B</code> change or are moved to a different class or class <code>B</code> is eliminated altogether, you have to modify <code>A</code> and <code>FOO1()</code> accordingly. By contrast, in the latter approach, <code>FOO2()</code> doesn't care whether class <code>B</code> exists, in fact all it cares about is that it is supplied with two floats (which in this case consist of <code>B.member1</code> and <code>B.member2</code>) and an int (<code>B.member3</code>). There is, to be sure, coupling in the latter example as well, but this coupling is handled by wherever <code>FOO2()</code> gets called or whatever class happens to be calling <code>FOO2()</code>, rather than in the definition of <code>A</code> or <code>B</code>. </p>
  
  <p>I guess a second part of this question is, is there a good way to decouple <code>A</code> and <code>B</code> further when we want to implement a solution like <code>FOO1()</code>?</p>