I am currently using a MySQL database and I have a DAO set up using the abstract factory pattern. It looks something like this:
public abstract class FactoryDAO {
public static final int MYSQL = 1;
...
public abstract CustomerDAO getCustomerDAO();
public static FactoryDAO getFactory(int whichFactory) {
switch (whichFactory) {
case MYSQL:
return new MySQLFactoryDAO();
...
}
}
public class MySQLFactoryDAO extends DAOFactory {
public static final String DRIVER= "com.mysql.jdbc.Driver";
public static final String DBURL="dbc:mysql://localhost";
public static Connection createConnection() {
return DriverManager.getConnection(DBURL, "user", "pass");
}
public UserDAO getCustomerDAO() {
return new MySQLCustomerDAO();
}
}
public interface CustomerDAO {
public void insertCustomer(Customer customer);
}
public class MySQLCustomerDAO implements CustomerDAO {
public int insertCustomer(Customer customer) {
//implementation
}
}
Now, I would like to add a new MySQL DAO to this factory because I need to use another MySQL database (with a different URL) but it has different operations. I wont have to insertCustomers()
but I will have to insertLogs()
. Is it possible with an abstract factory pattern?
Aucun commentaire:
Enregistrer un commentaire