So I've read Effective Java: Chapter 3. Methods Common to All Objects (a lot over the years :) ) and DDD from Erich Evans (a lot over the years :) ) And always follow the convention of comparing ids when writing equals functions for entities and for value types using the internal state / data of the object. So now we have a new challenge where we have an application with an existing rich domain model which should be persisted in the future. I have a very specific question about this where I am experiencing a bit of code writers block. There a few classes in there that have no identity with various pieces of information... a typical value object you might say... but also have references to other child objects (i.e. object graph). So it would usually be something like:
public class BeeskneesEntityA {
private Long id;
private Voj childV;
}
public class Voj {
private Long priceInCents;
private Long otherLong;
private BeeskneesEntityB childB;
}
public class BeeskneesEntityB {
private Long id;
...
}
- How would equals be written in this case ignoring for a moment that we will persist it? Should the child objects be navigated and also be checked for equality?
- What would be the best way to persist these objects? Give them an id?