mardi 29 mars 2016

Abstract Factory with two diferent model DB's

I'm using a Abstract FactoryPattern with two diferent DB Models (Oracle and DB2), according with this pattern I have to implement all of the methods for each factoryDAo, but I don't want to have the methods of Oracle in my FactoryDao DB2, because the DB model it's different.

Now the question is, what is the best practice in this case, how I have to implement this pattern to isolate both models?

FACTORY

    public abstract class DAOFactory {

        public static final int ORACLE = 1;

        public static final int DB2 = 2;

public abstract ApplicationDAO getApplicationDAO() throws HibernateException;
.
.


    public static DAOFactory getDAOFactory(int factory) {
            switch (factory) {

            case ORACLE:
                return new OracleFactoryDao();

            case DB2:
                return new Db2FactoryDao();
                }
            return null;
        }

FACTORYDAO

 public class OracleFactoryDao extends DAOFactory {

public ApplicationDAOImpl getApplicationDAO() {
        return new ApplicationDAOImpl();
    }
..}

    public class DB2FactoryDao extends DAOFactory {
public ApplicationDAOImpl getApplicationDAO() {
        return new ApplicationDAOImpl();
    }..}

Aucun commentaire:

Enregistrer un commentaire