Follow treslines by email clicking Here!

Sunday, February 26, 2012

When do we need DataTransferObjects - DTOs (indicators)

Indicators for DTOs (Data Transfer Objects)


DTO should be used with care. Generally we decide case by case, whether we shall introduce DTO layers which generates more complexity, or whether we work directly with the domain objects (DOs). The list below will assist us by our decission.


When can i use DomainObjects(DOs) direct to visualize details in the GUI?


Case 1: 
you can do it (and shall do it) by readonly views and if the domain object doesn't need to go back to the database. During this process the client may change values of the domain object if necessary. The only condition: The domain object is not returned to the database.


Case 2: 
If other software parts use the same service needing the whole content of a domain object. In this case you may get and use the whole domain object. But if you wanna change some values of it and store it back into the database, then you'll need new objects called: prefixDTOData. why that? Because otherwise we would force the service which writes the attributes into database to iterate over the whole domain object looking and comparing for changes before writing down in the database. 


When shall i better use DTOs? 


Case 1:
Use DTO's if the domain object is huge, but you just need a few attributes of it! For large domain objects, in which the client visualize, change or display only a few of its attributes. In this case we recommend to use the notation: prefixDTO. This is the object which the client uses to do its works. The service gets the Domain Object, creates the DTO and gives it back. If this DTO is used in a wizard or kind of formular in which the user may type something in setting values, which means that you have to store the typed information into database, then you should use in addtion to the DTOs new objects called: prefixDTOData. why that? Because otherwise we would force the service which writes the attributes into database to iterate over the whole domain object (remember that the domain object is huge) looking and comparing for changes before writing down in the database.


Case 2:
Use DTOs if the client has to show fields from different domain objects. In this special case you may consider putting all the needed attributes together already in the database creating the DTO in the server which is passed to the service going to the client. The client creates analoque to Case 1 a prefixDTOData an gives it back to the service. the reasons are the same as in explained in Case 1.


What are the disadvantages of DTOs?

You have/create additional complexities, which means that if things has to be changed, you have to make the changes everywhere in your code.



How can i motivate other developers ?

Well i do that by talking about, i wear my treslines.com t-shirt, i wear my bracelets with the CCD (Clean Code Developer Initials and colors) and i use my brand new treslines bag. It feels fantastic and even on the train people start talking to me asking about it. It is also a great idea to motivate agile teams and to share your expirience. You may want a great gift to show your appreciation to your team. Surprise them with a gadget from www.treslines.com. I love it.


Other interesting blogs

How could we improve the quality of this article ?

If the content of this article does not help you, so please tell us how to improve the quality of it by giving your contructive feedbacks at the end of this blog. If it was useful to you giving and resuming to you the most important aspects of the subject treated, saving you a lot of time, then help us to maintain this blog with a little appreciation. With a small amount of your choice you help us to cover the prime costs like:
Hosting, autors’s research work, editorial work, blog quality, motivation to make things better than others resulting in a very useful information pool for you and a lot of other developers. Important : If you do not have the possibility to donate a little amount, than recommend this page to your friends. Thanks !







Source code convention tools

Literature, good books and references

How can i subscribe/feed this blog ?

Subscribe : click on the link at the end of this blog

Want to stay up to date ?

How can i rate this blog ?

Press google+1 once !

Where do i find more clean code knowledge and gadgets?

 


2 comments:

  1. You should use the word "case" instead of "fall" ;)

    ReplyDelete