Reputation: 1397
I have a class which models a data transfer object, I have an object attribute in it which is based of a persistent class. Is it good practice to do that? Here's the class in question:
public class WorkRequest {
private Long id;
private String type;
private Worker worker;
private JobItem jobItem; // persistent class object
private Set<WorkQuantity> quantities;
public WorkRequest() {}
}
Upvotes: 2
Views: 524
Reputation: 10695
It is not good practice, because in general it is good to separate the domain model data from the data transported to other systems. Meaning if in the future you add some fields to JobItem class, you may accidentally also send them with your DTO to other systems causing data leaks or bugs.
However in many cases that concern does not matter much.
Upvotes: 1