If you choose this option, you will create one physical database table for each concrete class, in this example Cat and Dog. The abstract class will have no table of its own; instead, the abstract fields will be replicated on each of the concrete tables.
These classes are described in detail below. The concrete (Cat and Dog) implementation classes are reasonably straightforward, but the abstract (Animal) classes are more complex.
package curam.inheritance; import curam.inheritance.Animal; import curam.util.persistence.helper.SingleTableEntityImpl; import curam.util.type.DeepCloneable; abstract class AnimalImpl<DTLS_STRUCT extends DeepCloneable> extends SingleTableEntityImpl<DTLS_STRUCT> implements Animal { public void printName() { System.out.println("My name is " + getName()); } }
You may provide this implementation if there is any common behavior between your concrete classes which is identical.
Hence the implementation of Animal getters and setters cannot be implemented in a central place.
The class is parameterized with the name of the Dtls struct, to be supplied by the implementing subclass.
The class is package-protected and marked abstract. In this example the subclasses will be placed in the same code-package; if you require some of your subclasses to be in a different package, you will need to mark your abstract implementation class public.
If there is no common implementation logic, you may omit this class, and instead concrete classes will inherit from SingleTableEntityImpl (or some other suitable class) directly.