title: What is DAO factory pattern?
body: <p>I am aware of factory and abstract factory methods, but I want to create a DAO factory pattern in Java.</p>
  
  <ol>
  <li>I want to know its importance.</li>
  <li>Its usage</li>
  </ol>
  
  <p>I have checked <a href="http://www.oracle.com/technetwork/java/dataaccessobject-138824.html" rel="noreferrer">this link</a> but it is difficult for me to understand.</p>
  
  <p>Can anyone explain it with the help of an example?</p>
  
  <p><strong>Edit:</strong> Here is an example of DAO pattern as I understood it:</p>
  
  <pre><code>public interface UserDAO {
      public void insert(User user);
      public void update(User user);
      public void delete(int userId);
  }
  </code></pre>
  
  <p>Implementation:</p>
  
  <pre><code>public class UserDAOImpl implements UserDAO {
      @Override
      public void delete(int userId) {
          // delete user from user table
      }
  
      @Override
      public User[] findAll() {
          // get a list of all users from user table
          return null;
      }
  
      @Override
      public User findByKey(int userId) {
          // get a user information if we supply unique userid
          return null;
      }
  
      @Override
      public void insert(User user) {
          // insert user into user table
      }
  
      @Override
      public void update(User user) {
          // update user information in user table
      }
  }
  </code></pre>
  
  <p>Factory: </p>
  
  <pre><code>public class UserDAOFactory {
      public static UserDAO getUserDAO(String type) { 
          if (type.equalsIgnoreCase("jdbc")) {
              return new UserDAOImpl();
          } else {
              return new UserDAOImpl();
          }
      }
  }
  </code></pre>
  
  <p>Client side code:</p>
  
  <pre><code>User user=new User();
  user.setName("Jinoy P George");
  user.setDesignation("Programmer");
  user.setAge(35);
  //get a reference to UserDAO object
  UserDAO userDAO=UserDAOFactory.getUserDAO("jdbc");
  //call insert method by passing user object
  userDAO.insert(user);
  </code></pre>
  
  <p>Is this dao pattern correct?</p>
  
  <p>Where should I open connection and close it?</p>