N
Navaneeth.K.N
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
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