vendredi 19 mai 2017

How we should handle the DTO?

I have 2 table, Patient and Registration and the relationship is one-to-many.

In the Registration module when I want to edit the registration, I call GetRegistrationByID(int id) to get the data by its ID and also select the PatientCode and PatientName and parse it to DTO.

In another module, I reuse the GetRegistrationByID(int id) but I need more information on the Patient's information such as gender, place and date of birth, address, village, district, province, and phone no.

I have 2 options for this case, change the RegistrationDTO to include more Patient's information but the consequence is in registration module when I call the GetRegistrationByID(int id) the RegistrationDTO is become bigger. Because I only need PatientCode and PatientName, and now there are extra information which is not necessary.

The second option is I create another method GetPatientInfoByRegistrationID(int id) but the consequence is there are 2 times round-trip to database. I think it violetes the DTO principle

A data transfer object (DTO1[2]) is an object that carries data between processes. The motivation for its use is that communication between processes is usually done resorting to remote interfaces (e.g. web services), where each call is an expensive operation.[2] Because the majority of the cost of each call is related to the round-trip time between the client and the server, one way of reducing the number of calls is to use an object (the DTO) that aggregates the data that would have been transferred by the several calls, but that is served by one call only.[2]

I'm trying to learn how to make the code better, so which one should I choose? Please add the explanation why it's better

Aucun commentaire:

Enregistrer un commentaire