the idea is the following. In my system I have to make the ABM of several objects, such as User, Card, Establishment, among others. I was reading about some pattern designs and I wanted to use it in my code so that, instead of doing the ABM of each one, I could generalize it and be useful for any class.
I did something similar with a search method to know if an object is already in an array. I stay this way:
public static Object buscar(List<?> fuente,Object aBuscar){
int tmp=fuente.indexOf(aBuscar);
return (tmp==-1)? null:fuente.get(tmp);
}
In case the object is in the array (I have the index provided by the indexOf()
method), it returns the pointer, otherwise it returns null
I want to do something similar but I have a problem when I want to modify the content, since I specifically need the type of class and the data to replace that class. How could I do it?
I leave the code of the high and low methods. If this is bad programming practice, please tell me and what would be the correct way.
public static void alta(ArrayList<Object> lista, Object datos){
if(!existe(lista, datos))/*Verifica si el objeto existe en el array*/
lista.add(datos);
}
public static void baja(ArrayList<Object> lista, Object datos){
lista.remove(datos);
}
Thank you in advance.