Hi Community, I have a design question, newbie-type:
In my app I have, for example, two POJO classes:
Cat, Dog
no matter their properties and methods. Then I have a controller:
AnimalController
in this class I have methods such as
getCat, getDog, setCat, setDog, editCat, editDog
In setDog I have something like this:
Code:
public Dog setDog(String color, int type) {
startTransaction();
Dog d = null;
try {
d = new Dog();
d.setValue(value);
d.setType(type);
session.save(d);
commitTransaction();
} catch (HibernateException he) {
rollbackTransaction();
he.printStackTrace();
throw he;
}
return d;
}
Obviously this works fine. But I have to write the same code for Cat. The question is:
Is there a way to write, without interfacing Dog and Cat in a common Animal interface, an abstract method like this:
Code:
public Object setObject(String ClassName, String color, int type) {
startTransaction();
ObjectOfTheTypeInClassName d = null;
try {
d = new ObjectOfTheTypeInClassName();
d.setValue(value);
d.setType(type);
session.save(d);
commitTransaction();
} catch (HibernateException he) {
rollbackTransaction();
he.printStackTrace();
throw he;
}
return d;
}
thank u in advance, hope that max doesn't reply telling me that there is a previous post similar to this. ;)