title: java's typing system: prefer interface types to class types as method parameters/return values
body: <p>I just making an effort to understand the power of the interfaces and how to use them to the best advantage. </p>
  
  <p>So far, I understood that interfaces: 
  <strong>enable us to have another layer of abstraction</strong>, <strong>separate the what</strong> (defined by the interface) and the <strong>how</strong> (any valid implementation). </p>
  
  <p>Given just one single implementation I would just build a house (in one particular way) and say here, its done instead of coming round with a building plan (the interface) and ask you, other developers to build it as i expect.</p>
  
  <p>So far, so good. </p>
  
  <p>What still puzzles me is why to favor interface types over class types when it comes to method parameters and return values. Why is that so? What are the benefits (drawbacks of the class approach)? </p>
  
  <p>What interests me the most is how this actually translates into code. </p>
  
  <p>Say we have a sort of pseudo mathInterface</p>
  
  <pre><code>public interface pseudoMathInterface {
  
  double getValue(); 
  
  double getSquareRoot(); 
  
  List&lt;Double&gt; getFirstHundredPrimes(); 
  
  }
  
  //...
  
  public class mathImp implements pseudoMathInterface { }
  //.. actual implementation 
  </code></pre>
  
  <p>So in the case of getPrimes() method I would bound it to List, meaning any concrete implementation of the List interface rather than a concerete implementation such as ArrayList!?</p>
  
  <p>And in terms of the method parameter would I once again broaden my opportunities whilst ensuring that i can do with the type whatever i would like to do given it is part of the interface's contract which the type finally implements.!?</p>