Let's say I want to create a shop/order system.
I'll have an Order
DTO to which I'll map the data from a request and results from the database.
The object will consist of an order number, a customer number and a list of articles.
The order number is pretty simple, I'll just use an int to store the number. But what about the customer? I'll also have a Customer
DTO so I could use it inside of the Order
DTO instead of saving the customer number as int.
In my case the customer number consists of a store_no (the store where the customer is registered) and a customer_no (store internal customer number).
To me it seems to be cleaner to have a structure which looks like this:
Order {
int order_no;
Customer cust;
}
Customer {
int store_no;
int cust_no;
}
instead of this:
Order {
int order_no;
int store_no;
int cust_no;
}
Customer {
int store_no;
int cust_no;
}
My problem:
The Customer
DTO will have a lot more information than just the customer number. Like a first name, last name, address, user name, some flags and so on. Things I don't care about when I just want to save an order with order_no 123 for the customer with store_no 12 cust_no 543.
So in this case using the Customer
DTO inside of the Order
DTO seems to be 'too much'.
Same goes for the articles.
Are there any best practices how to create such DTOs? Encapsulate DTOs or repeat the same information in different DTOs?