I'm trying to reduce the code duplication that exists throughout my asp.net web forms. This is what an example object loaded from the database looks like.
Apartment
int id
decimal rent
bool callForPricing
int squareFeet
int beds
int baths
Now I create views from this object in several different asp.net pages (ie. a list with several apartments, a detail view, etc). In the past what I have done is create another class that wraps the Apartment class. Something like this...
ApartmentView
Apartment apt
public virtual String Rent
{
get
{
if (apt.CallForPricing)
{
return "Call For Pricing";
}else{
return apt.Rent.ToString("C") + "/Month";
}
}
}
public virtual String BedsBathsSqFt
{
get
{
if (apt.squareFeet > 0)
{
return apt.beds + " Beds|" + apt.beds + " Beds|" + apt.SquareFeet + " sqft";
}else{
return apt.beds + " Beds|" + apt.beds + " Beds";
}
}
}
As you can see I'm usually just creating string representations of the data. I have considered having the ApartmentView class extend the Apartment class, but haven't because of overlapping properties like 'Rent'. I'm just wondering how people normally deal with this situation. Is this the correct naming convention to use?