Dofactory.com
Dofactory.com
 Back to list
Views:   16.1K
Replies:  3
Archived

Data Transfer Objects and Service Layer

Question about the Design Pattern Framework.

What is the purpose of the Data Transfer Objects in the Service Layer?
If I'm not using WCF is it possible to eliminate the DTOs in the Service Layer?
In the code we have:
var categories = _categoryDao.GetCategories();
response.Categories = Mapper.ToDataTransferObjects(categories);

If we did not use WCF we could we simply use:
return _categoryDao.GetCategories();


Thanks
Dennis
Dennis Tucker, Jun 11, 2012
Reply 1
Hi, Dennis.

DTO's are for sending data across layers and is independent of WCF. They're great in cases where you need to add more data members, as your interface is not broken and, assuming you're employing versioning, can access the new members in your updated methods.

Mike
Michael Lopez, Aug 04, 2012
Reply 2

The Dto, for me at least, helps to enforce separation of concerns and in my view are used to

Passing Data between layers using serializable objects - helps with scaling if required later

Stopping business objects being passed from the service layer to the presentation layer

William Jones, Jul 26, 2012
Reply 3
Hi,

Data Transfer Object or DTO's are mainly used for sending information from one layer to another layer. It doesn't have any relation with WCF services.

Also, I have seen people uses DTO's in two ways:
  1. Keep common class for each layers and pass the information.
  2. Keep separate class for each layers and hide the information wherever you need.

Both approaches has its pros and cons. It totally depends on your choice what you need.

Vishal Shah, Jun 18, 2012
Stay Inspired!
Join other developers and designers who have already signed up for our mailing list.
Terms     Privacy     Cookies       Do Not Sell       Licensing      
Made with    in Austin, Texas.  - vsn 44.0.0
© Data & Object Factory, LLC.