Interfaces and Generics for a Service
Interfaces and Generics for a Java Service
Complex inheritance schemes can cause a lot of problems when two objects share a same root, but diverge too much from each other.
Model
A model composed of:
Interface
JPA entity
DTO with additional fields
public interface ModelObject {
public String getName();
public void setName(final String name);
}
@Entity
public class ModelObjectEntity implements ModelObject {
// Class prepared for persistence
public Integer getId() {
return id;
}
}
public class ModelObjectAdditionalField implements ModelObject {
// Implements the interface, but adds a field
public Integer getDate() {
return date;
}
}Service
Usage
Last updated
Was this helpful?