名前を変更するのは完全にあなた次第です。DAOパターンは、必ずしもデータベースアクセスである必要はないあらゆるタイプのデータアクセスを抽象化します。だからあなたは間違いなくあなたの計画を進めることができます。
パターンを手動で作成する代わりに、Springのようなフレームワークを使用できます。
これらのパターンを一度だけハードコーディングしてみました。
public abstract class DAOFactory {
// List of DAO types supported by the factory
public static final int MYSQL = 1;
public static final int ORACLE = 2;
public abstract UserDAO getUserDAO() throws SQLException;
public static DAOFactory getDAOFactory(int whichFactory) {
switch (whichFactory) {
case MYSQL:
return new MySQLDAOFactory();
case ORACLE :
......
public class MySQLDAOFactory extends DAOFactory {
public MySQLDAOFactory() {
}
public static final String DRIVER= "/*driver here*/";
public static final String DBURL="/*conn string here*/";
/* instead of using constants you could read them from an external xml file*/
public static Connection createConnection() {
/*create connection object here*/
return conn;
}
public UserDAO getUserDAO() throws SQLException{
return new MySQLUserDAO();
}
public interface UserDAO {
public int insertUser(String fname, String lname);
public ArrayList<User> selectUsers();
}
public class MySQLUserDAO implements UserDAO {
Connection conn=null;
Statement s=null;
public MySQLUserDAO() throws SQLException{
conn = MySQLDAOFactory.createConnection();
s = conn.createStatement();
}
public int insertUser(String fname, String lname)
{
//implementation
}
public ArrayList<User> selectUsers()
{
//implementation
}