Why do setters work poorly in interfaces if we talk about domain objects?
Clarification:
I have a domain object that is stored in db. It has several fields that are very expensive. I.e.
class JurasicPark {
private long area;
...other fields ...
getters and setters
....
private Collection<Dinosaur> dinosaurs;
private Collection<ExoticTree> flora;
public Collection<Dinosaur> getDinosaurus(){
...
}
public Collection<ExoticTree> getFlora(){
...
}
}
Fields dinosaursand floravery expensive to initialize and install. But in many cases, I do not need these fields, which need to be set every time.
The problem is that if I go back to the custom instance of the JurasicPark class with dinosaursor flora, don't initialize it to populate the listing with either NPE or some kind of presentation that I throw away. I do not want the api user to think about this and remember which fields may not be set.
, , IJurasicPark IFullJurasicPark, , flora dinosaurs.
interface IFullJurasicPark extends IJurasicPark
class IJurasicPark implements IFullJurasicPark
IJurasicPark , , ?
LazyInit.