I would suggest you create 2 bases classes, 1 for entity, 1 for VO.
Example:
public abstract class Entity implements Serializable {
}
public abstract class AbstractVO {
}
Then, use a Abstract Factory pattern for each object's Factory
public AbstractFactory {
private AbstractFactory() {}
public abstract Factory getFactory(Class clazz) {
if (Entity.class.isAssignableFrom(clazz)) {
return new EntityFactory();
}
if (AbstractVO.class.isAssignableFrom(clazz)) {
return new VOFactory();
}
return null;
}
}
I am using a Class.isAssignableFrom() method to say that subclassed classes is assignable from the parent class (which it does, if you understand what I'm trying to say). That's the trick here.
For this, I would make a Factory for each object
public abstract Factory<T> {
public abstract T createObject();
}
public class EntityFactory extends Factory<Entity> {
public Entity createObject(Class entityClass) {
try {
return entityClass.newInstance();
} catch (Exception e) {
e.printStackTrace();
}
}
}
public class VOFactory extends Factory<AbstractVO> {
public AbstractVO createObject(Class voClass) {
try {
return voClass.newInstance();
} catch (Exception e) {
e.printStackTrace();
}
}
}
Finally, getting the object
Entity entity = (Entity)AbstractFactory.getFactory(Entity.class).createObject();