When I came across these messy data models, I was really confused. The architecture design was also chaotic, and I didn't know how to derive the corresponding package names based on the data models. I also browsed various materials online, but no one explained it in a simple and understandable way, so I 整理了一下 based on my experience.
POJO
【plain old java object】ordinary Java object, can serve as the basis for other data modelsVO
【value object】: A value object is an immutable object, with no unique ID identifier, used to represent a set of values【which means that if two value objects have the same properties, they are equal】- Can contain simple business logic operations
- VO usually overrides equals and hashCode methods for value-based comparison
PO / Entity
【Entity】: An entity must have a unique ID identifier, which means that if two entities have the same property values, they are not equal; PO is a Java object that maps to a database table【so PO and entity can be considered the same concept】DTO
【data transfer object】: DTO is used to transfer data between different layers- Does not contain any business logic
Rich Model
: Rich model = PO + business logic,if a PO contains business logic, then it is a rich modelBO
【Business object】: A business object contains business logic- Used only in the Service layer