CatImpl

Figure 1. One table per concrete class - implementation of concrete class
package curam.inheritance;

import curam.inheritance.Cat;
import curam.inheritance.struct.CatDtls;

public class CatImpl extends AnimalImpl<CatDtls> implements Cat {

  protected CatImpl() {
  }

  public int getNumberOfLivesRemaining() {
    return getDtls().numberOfLivesRemaining;
  }

  public void setNumberOfLivesRemaining(final int value) {
    getDtls().numberOfLivesRemaining = value;
  }

  public String getName() {
    return getDtls().name;
  }

  public void setName(String value) {
    getDtls().name = value;
  }

  public void speak() {
    System.out.println("Miaow!  My name is " + getName()
        + " and I have " + getNumberOfLivesRemaining()
        + " lives remaining");
  }

  public void crossFieldValidation() {
    // none required
  }

  public void crossEntityValidation() {
    // none required
  }

  public void mandatoryFieldValidation() {
    // none required
  }

  public void setNewInstanceDefaults() {
    // none required
  }

}

Class declaration

public class CatImpl extends AnimalImpl<CatDtls> implements Cat {
The class:
  • extends the AnimalImpl class created above, specifying the CatDtls struct as a parameter; and
  • implements the Cat interface (which in turn extends the Animal interface).

Protected constructor

protected CatImpl() {
  }

The class has a protected constructor, as is the norm for the implementation classes.

Getters and Setters

The getters and setters make use of the regular SingleTableEntityImpl.getDtls method to access the CatDtls row data.

Getters and setters are supplied for both:
  • Cat -specific fields; and
  • fields common across all Animal types.

speak

public void speak() {
    System.out.println("Miaow!  My name is " + getName() +
      " and I have " + getNumberOfLivesRemaining() +
      " lives remaining");
  }

This class must provide an implementation of the Animal.speak method.