title: Correct design of classes built for testability using constructor injection
body: <p>Say I have these 3 layers of my code:<br>
  1. Database layer (ORM)<br>
  2. BusinessLogic<br>
  3. Application</p>
  
  <p>Now, I write my code as follows:</p>
  
  <ol>
  <li><p>Database layer:<br>
  This mainly has CURD operations over database.</p>
  
  <pre><code>class MyDatabaseLayer {
      public int findValue(int k) {
          // find v
      }
  
      public void insertValue(int k, int v) {
          // Insert v
      }
  }
  </code></pre></li>
  <li><p>BusinessLogic:<br>
  This holds the actual logic to call database layer and do stuff.</p>
  
  <pre><code>class MyBusinessLogic {
      private MyDatabaseLayer dbLayer;
      public MyBusinessLogic(MyDatabaseLayer dbLayer) {
          this.dbLayer  = dbLayer;
      }
  
      public int manipulateValue(int k) {
          dbLayer.findValue(k);
          //do stuff with value
      }
  }
  </code></pre></li>
  <li><p>Application layer:<br>
  This calls the business logic and displays the data  </p>
  
  <pre><code>MyBusinessLogic logic = new MyBusinessLogic(new MyDatabaseLayer ()); //The problem
  logic.manipulateValue(5);
  </code></pre></li>
  </ol>
  
  <p><strong>Now if you see in the application layer, it knows about the database layer, which is wrong. It knows too much.</strong></p>
  
  <p>Misko Hevery <a href="http://misko.hevery.com/2009/02/19/constructor-injection-vs-setter-injection/" rel="nofollow">says</a>: Constructor injection is good. But if I follow that, how will I achieve abstraction? And how can Google Guice help me here?</p>