Forum
 
ForumForumDiscussions and...Discussions and....Net framework ....Net framework ...Passing data between application layersPassing data between application layers
Previous Previous
 
Next Next
New Post
 15/03/2008 05:01
 

Hi

How do you prefer to pass data between layers of a web application?

  • Business object - with behaviour
  • Business object - without behaviour (i.e. Data Transfer Object, DTO)
  • DataTable
  • XML
  • SqlDataReader

Something else?

Chris

New Post
 16/03/2008 17:09
 

I like Business Object and I'm not fussy about whether it has behaviour or not.


Cheers,
- Richard
If this post helped you over a problem, or taught you something new, please login and rate it. Ratings are in the drop down in the top left corner
New Post
 25/03/2008 00:39
 

I suspect there isn't one right answer. If you're looking for interoperability, for instance, your first choice should be XML. One of the nice things about passing a DataTable is that you're actually passing XML. It's just that, in a .NET environment, .NET will automatically wrap up the XML in a custom object (the DataTable object) that makes working with the XML document considerably easier for client-side developers.

If you're not interested in interoperability, passing an object is a better choice. Developers writing client-side code will find it much easier to work with a business object than a raw XML document. In general, I don't think that you should pass any more than you absolutely have to so I wouldn't pass an object with behaviour (another problem with passing an object with behaviour is that you may find yourself building an object that will need to support both client- and server-side activity).  If you are concerned about getting behaviour down to the client (either to make life easier for your client-side developers or to prevent client-side developers from sending back bad data) then build in only client-side behaviour and use the Factory pattern so that all server-side behviour is encapsulated in the factory object.

Having said that the right answer is "It depends", I don't think you should ever pass a Framework object like the SqlDataReader. Because you don't control the construction of the SqlDataReader you have no idea what developers who recieve that object will be able to do with it. The DataTable is, essentially, an XML document--the SqlDataReader is an access point to your database.

Previous Previous
 
Next Next
ForumForumDiscussions and...Discussions and....Net framework ....Net framework ...Passing data between application layersPassing data between application layers

Forum Usage Guidelines

The forums are a place for all to exchange ideas and techniques, and to post and answer questions.  All are welcome to read, registration is required to post. 

If you learn somthing new, discover or acquire a new technique, then please take a moment to register and rate the post that just helped you.  This site does not send spam and it does not release your personal details.  Full details in the site privacy policy.

We have some simple posting guidelines to keep the forums a pleasant and informative environment.

  • No flames, no trolls
  • No profanity, no racism
  • Site management has the final word on approving or removing any thread, post, or comment
  • English language only please

 

Copyright 2002-15 by Dynamisys Ltd