Android: How do I allow access to only part of an objects members using an interface
<p>How do I "pass an interface", i.e. what CommonsWare suggested to the asker in the <a href="http://stackoverflow.com/questions/2719433/getting-reference-to-calling-activity-from-asynctask-not-as-an-inner-class">question below</a>?></p>

<blockquote>
  <p>The other is to make DownloadFileTask
  public and pass something into the
  constructor. In this case, to minimize
  coupling, it may be that you don't
  want to pass an Activity, <strong>but some
  other sort of interface that limits
  what the AsyncTask can do.</strong> That way,
  you can choose to implement the
  interface on an Activity, or as a
  separate object, or whatever. –
  CommonsWare Apr 27 '10 at 17:44</p>
</blockquote>

<p>How do I allow a thread to access to only some (or just one) of the objects public methods?</p>

<p>Answer> See the answers below. </p>

<p>The real problem was my misunderstanding of what an interface does. If the input type of a method F (or parameterization of a class) is specified as an interface [i.e. F(my_interface i)], and an object X is passed to that method which implements my_interface [F(X)], then only the members of X which implement my_interface will be accessible to the method F even if other members exist. </p>

<p>I thought an interface put a constraint only on the implementing class. I didn't understand that when an interface was used as a type it would also constrict access to the members of the implementing class. In retrospect, given that Java is statically typed this is obvious. See the <a href="http://download.oracle.com/javase/tutorial/java/IandI/summary-interface.html" rel="nofollow">Java tutorial</a> for more info.</p>
