DAO interfaces

You require to:

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):

Figure 1. The DAO interface for Cat
package curam.inheritance;

import java.util.Set;

import curam.util.persistence.StandardDAO;

public interface CatDAO extends StandardDAO<Cat> {

  public Set<Cat> readAllCats();

}
Figure 2. The DAO interface for Dog
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:

Figure 3. The read-only DAO interface for Animal
package curam.inheritance;

import java.util.Set;

import curam.util.persistence.ReaderDAO;

public interface AnimalDAO extends ReaderDAO<Long, Animal> {

  public Set<Animal> readAllAnimals();

}
Note: Unlike the Animal/Cat/Dog interfaces, the DAO interfaces for Animal/Cat/Dog do not form an inheritance hierarchy.