When you use a lightweight class like this, where does the business logic lie?
In my standard way of doing things, I would inherit your class from a DataItem class that provides a Save() and Load() method that call pure virtual StoreItem and LoadItemFromDataStore. Then in Customer, StoreItem would call into my DAL with:
dataLayerClass.StoreCustomer(name, address1, etc...) or dataLayerClass.LoadCustomer(id)
Thus, my classes are slightly "heavier" than yours but it seems like a clean separation of the data layer from the presentation. If you take the lightweight class and do a save you would have to do:
dataLayerClass.StoreCustomer(Customer c)
Doesn't that violate some rule, somewhere!? LOL!
Finally, what exactly is too "heavy-weight" for code behind? If you move the business logic into a business class, but it's now too heavy, don't you have to call that logic in the .StoreCustomer method to validate data, etc... Now .StoreCustomer is being called from presentation and it's heavy instead...
Thanks for clarifying.
datakix:
I wouldn't worry about 2 users concurrently submitting the form at the same time and getting mixed up - the .NET Framework along w/the ASP.NET SessionID will handle that for you. However, you may want to avoid using a 'struct' datatype in that fashion as it handcuffs your extensibility.
See: http://www.csharp-station.com/Tutorials/Lesson12.aspx
In general, when you collect user data you don't want to mix the presentation layer code and the business logic code. Moreover, you don't want to complicate the presentation layer with complex data types as it does add some overhead. Unless there is a real business need, I'd recommend keeping it simple and just populating a class you carry around in session after the user posts their data. Below is an example Customer class:
public class Customer
{
private string _VisualID;
private string _FirstName;
private string _MiddleName;
private string _LastName;
private string _Street1;
private string _Street2;
private string _City;
private string _State;
private string _Zip;
private string _CountryCode;
private string _Phone;
private string _Email;
private string _DOB;
private string _IsPrimary;
/// //////////////////////////////////////////////////////////////
/// <summary>
/// Constructor
/// </summary>
/// //////////////////////////////////////////////////////////////
public Customer()
{
//
// TODO: Add constructor logic here
//
}
/*
* //////////////////////////////////////////////////////////
* Accessor / Mutator methods
* //////////////////////////////////////////////////////////
*/
public string VisualID
{
get
{
return _VisualID;
}
set
{
_VisualID = value;
}
}
public string FirstName
{
get
{
return _FirstName;
}
set
{
_FirstName = value;
}
}
public string MiddleName
{
get
{
return _MiddleName;
}
set
{
_MiddleName = value;
}
}
public string LastName
{
get
{
return _LastName;
}
set
{
_LastName = value;
}
}
public string Street1
{
get
{
return _Street1;
}
set
{
_Street1 = value;
}
}
public string Street2
{
get
{
return _Street2;
}
set
{
_Street2 = value;
}
}
public string City
{
get
{
return _City;
}
set
{
_City = value;
}
}
public string State
{
get
{
return _State;
}
set
{
_State = value;
}
}
public string Zip
{
get
{
return _Zip;
}
set
{
_Zip = value;
}
}
public string CountryCode
{
get
{
return _CountryCode;
}
set
{
_CountryCode = value;
}
}
public string Phone
{
get
{
return _Phone;
}
set
{
_Phone = value;
}
}
public string Email
{
get
{
return _Email;
}
set
{
_Email = value;
}
}
public string DOB
{
get
{
return _DOB;
}
set
{
_DOB = value;
}
}
public string IsPrimary
{
get
{
return _IsPrimary;
}
set
{
_IsPrimary = value;
}
}