I'm creating a series of classes that return listings in Java (Android).
I'm worried about the format of the parameters that will be passed. My initial approach has been to pass Map
with parameters, this way
I can add or remove parameters without major changes to the layers.
public List<PlPg> getLista(SQLiteDatabase p_db,Map<String, Object> parametros)
But what has been boring is that whenever I call this function I need to 'check' the name of the keys of the parameters that are used inside the function.
// Aqui eu pego os parâmetros do map.
int pzmax = (Integer)parametros.get("pzmax");
int cliente = (Integer)parametros.get("cliente")
// Mas aqui, na hora de gerar o Map de parâmetros preciso conhecer as keys .
Map<String, Object> parametros = new HashMap<String, Object>();
parametros.put("pzmax", p_pzmax);
parametros.put("cliente", p_cliente);
parametros.put("plpgpadrao", p_plano);
My alternative idea would be to get - instead of a Map
- an object that has methods that return the values of the filters.
public List<PlPg> getLista(SQLiteDatabase p_db,IFiltroPlpg pFiltro);
//Essa seria interface q retorna os dados dos filtros
public interface IFiltroPlpg {
int pzmax();
int cliente();
int planoPadrao();
}
But with this approach, I need to create a filter class for each listing configuration, with different getters.
I would like to know which of these approaches would be most appropriate from the point of view of best OOP practices, or whether there are other better options than this.