jeudi 29 octobre 2015

Error "cannot be resolved to a type" using the Factory Methond

I'm trying to use the design pattern "Factory Method" on DAO. There are some problems with the type resolving when I call the method to create the correct instance. This is the main where I call the method and I get the error:

public class Main {

public static void main(String[] args){
    int scelta=1;

    Parametri<InterfacciaTO> p=new Parametri<InterfacciaTO>();
    //here I get the error
    DaoInterface dao=(DaoInterface) new MySqlDAO.getInstance(scelta,p);


}

}

These are the classes that I use to implement the FactoryMethod.

public interface DaoFactory {

    public abstract Object getInstance(int code,Parametri<InterfacciaTO> param);

}

public  class MySqlDAO implements DaoFactory {

@Override
public DaoInterface getInstance(int code, Parametri<InterfacciaTO> param) {
    switch(code){
    case Indici.UTENTEDAO: return new UtenteDAO();
    }
    return null;
}   
}

public interface DaoInterface {

public abstract void create(int code,Parametri<InterfacciaTO> param);

public abstract void delete(int code,Parametri<InterfacciaTO> param);

public abstract void update(int code,Parametri<InterfacciaTO> param);

public abstract void search(int code,Parametri<InterfacciaTO> param);

}

public class UtenteDAO implements DaoInterface {

@Override
public void create(int code, Parametri<InterfacciaTO> param) {
    System.out.println("CIAU");

}

@Override
public void delete(int code, Parametri<InterfacciaTO> param) {
    // TODO Auto-generated method stub

}

@Override
public void update(int code, Parametri<InterfacciaTO> param) {
    // TODO Auto-generated method stub

}

@Override
public void search(int code, Parametri<InterfacciaTO> param) {
    // TODO Auto-generated method stub

}

}

Aucun commentaire:

Enregistrer un commentaire