title: How to design a DAO class?
body: <p>What should be the best way to design a DAO class ?</p>
  
  <p><em><strong>Approach#1:</em></strong> <em>Design DAO class as an object</em>.</p>
  
  <pre><code>class Customer {
  //customer class
  }
  
  class CustomerDAO {
    public void saveCustomer(Customer customer) {
    //code
    }
  
    public Customer getCustomer(int id) {
    //code
    }
  }
  
  //Client code
  class client {
    public static void main(String[] args) {
  
     CustomerDAO customerDAO = new CustomerDAO();
     Customer customer = new Customer();
     customerDAO.saveCustomer(customer);
    }
  }
  </code></pre>
  
  <p><em><strong>Approach#2:</em></strong> <em>Design DAO class with static methods</em> (aka static class)</p>
  
  <pre><code>class Customer {
  //customer class
  }
  
  class CustomerDAO {
    public static void saveCustomer(Customer customer) {
    //code
    }
  
    public static Customer getCustomer(int id) {
    //code
    }
  }
  
  //Client code
  class client {
    public static void main(String[] args) {
  
     Customer customer = new Customer();
     CustomerDAO.saveCustomer(customer);
    }
  }
  </code></pre>
  
  <p>In approach#1, I have to create an object of DAO class in all the client code (other option is to pass the reference of DAO all around). while in approach#2, I do not have to create the object and the static methods can be designed with no state tracking.</p>
  
  <p>So which approach is the best in design of DAO classes ? </p>