The creation and retrieval of Cat and Dog instances is straightforward - create DAO interfaces for Cats and Dogs (you can also include other retrievals too):
package curam.inheritance; import java.util.Set; import curam.util.persistence.StandardDAO; public interface CatDAO extends StandardDAO<Cat> { public Set<Cat> readAllCats(); }
package curam.inheritance; import java.util.Set; import curam.util.persistence.StandardDAO; public interface DogDAO extends StandardDAO<Dog> { public Set<Dog> readAllDogs(); }
The DAO interface for Animal is slightly different in that callers can retrieve a generic Animal based on its ID (and the implementation will be responsible for creating a Cat or Dog object as appropriate), but callers cannot create an Animal (all creations must create either a concrete Cat or a concrete Dog).
Use the ReaderDAO interface instead of StandardDAO:
package curam.inheritance; import java.util.Set; import curam.util.persistence.ReaderDAO; public interface AnimalDAO extends ReaderDAO<Long, Animal> { public Set<Animal> readAllAnimals(); }