Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / May 2008

Tip: Looking for answers? Try searching our database.

Data transfer objects in C#

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Navaneeth.K.N - 26 May 2008 11:53 GMT
Hi

I am learning DTO and wrote a dto for my "Product" class. I want to know
whether I am following the right method ? Here is my code

class Product
{
  internal Product(ProductItem item)
  {
     this.Name = item.Name;
  }
 
  public string Name
  {
      get;set;
  }

  public static Product FromId(int productId)
  {
     ProductDAL data = new ProductDAL();
     ProductItem item = data.GetProductFromId(productId);
     return ProductFactory.CreateProduct(item);
  }

   public void Save()
   {
      ProductDAL data = new ProductDAL();
      ProductItem item = new ProductItem(this.Name);
      data.SaveDetails(item);
   }

}

static class ProductFactory
{
  public static CreateProduct(ProductItem item)
  {
     Product product = new Product(item);
     return product;
  }
}

// DTO class
class ProductItem
{
   public ProductItem(string name)
   {
      this.Name = name;
   }

   public string Name
   {
      get;set;
   }
}

Do you write any methods in the DTO class  ? Or only some getters and
setters ?

Thanks
jj - 26 May 2008 12:33 GMT
Hello Navaneet, I'll put in my 2 cents..

DTOs are strictly used for TRANSFERRING data. Think of it as a data
structure. The code for fetching or saving data should not be in a
DTO. It should be in DAL objects, and invoked from BLL objects.

Regards,
Jim
Navaneeth.K.N - 26 May 2008 13:30 GMT
Hi Jim,

Thanks for replying me. I don't have Save functionality in DTO class.
"ProductItem" is the DTO class which contains only the data structure. So is
this correct approach ?

> Hello Navaneet, I'll put in my 2 cents..
>
[quoted text clipped - 4 lines]
> Regards,
> Jim
jj - 30 May 2008 11:48 GMT
Hello Navaneet,

Your ProductItem class is a DTO. there is nothing wrong with it. Just
remember to mark your DTO classes as serializable if you want to send
them using web services or remoting. I know you know about this, but
just a reminder.

Regards,
Jim

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.