You can make an abstract parameterized class. For example, here's a Person object class:
Code:
public abstract class Person<ID extends Serializable> {
ID id;
String name;
Date birthDate;
public abstract ID getId();
public abstract void setId(ID id);
//getXxx() and setXxxx() here.
}
When you create an Employee class (also a Person), do it like this:
Code:
public class Employee extends Person<Integer> {
Integer id;
public Integer getId() {
return this.id;
}
public void setId(Integer id) {
this.id = id;
}
//inherited name, birthDate properties and accessors;
}
Or, a UserLogin class for authentication:
Code:
public class User extends Person<String> {
private String id;
public String getId() {
return this.id;
}
public void setId(String id) {
this.id = id;
}
... //the rest of the code.
}
This is not always applicable to every entity class.